Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中将代码块捕获到字符串变量中_Python_Html_Json - Fatal编程技术网

在python中将代码块捕获到字符串变量中

在python中将代码块捕获到字符串变量中,python,html,json,Python,Html,Json,我想动态创建html代码块,但不确定如何将其分配到变量: <head> <style> body { border-style: solid; border-width: 5px; border-color: green; border-radius: 5px; border-spacing: 30px; background-color: #FFFFC2; padding-bottom: 5px; font

我想动态创建html代码块,但不确定如何将其分配到变量:

<head>
<style>
body {
    border-style: solid;
    border-width: 5px;
    border-color: green;
    border-radius: 5px;
    border-spacing: 30px;
    background-color: #FFFFC2;
    padding-bottom: 5px;
    font-size: 25px;
}

li {
    color: #F7270F;
    font-weight: bold;
}
</style>
</head>
<body>
<div style="margin-bottom: 5px; margin-top: 5px; margin-left: 10px; margin-right: 10px;">
<h1 align="center">Auctions for Week of 08-01-2018</h1>
<p>You are bidding on the following item:</p>
<ul><li>This is the item for sale</li></ul>
<p>Condition is pack fresh unless otherwise indicated. Please review the pictures carefully and if you have any questions about something specific, ask.</p>
<p><b>Shipping:</b> Shipping will be calculated based on buyer location. No premiums are charged. Cards are mailed in an 8x5 bubble mailer and shipped First Class mail unless the price exceeds $50, at which point they will be shipped Priority at no additional cost to the buyer. If you win multiple auctions, please wait for an invoice to be sent.</p>
</div>
</body>

身体{
边框样式:实心;
边框宽度:5px;
边框颜色:绿色;
边界半径:5px;
边界间距:30px;
背景色:#FFFFC2;
垫底:5px;
字体大小:25px;
}
李{
颜色:#F7270F;
字体大小:粗体;
}
2018年1月8日一周的拍卖
您正在对以下项目进行投标:

  • 这是待售商品
    • 除非另有说明,否则包装条件为全新。请仔细阅读图片,如果您有任何关于特定内容的问题,请询问

      装运:装运将根据买方所在地进行计算。不收取保险费。除非价格超过50美元,否则卡将在8x5气泡邮递器中邮寄,并以头等邮件方式寄送,此时将优先寄送,买方不承担任何额外费用。如果您赢得多次拍卖,请等待发票发送

我试过执行:

html\u desc=”“


但它不喜欢这样的工作方式。。。所以我有点困惑。我试图将其放入变量中的原因是,我需要将其作为JSON语句的键值。

您可以将该代码块放入三重引号
“”“
(例如,我将变量放入
JSON.dumps
):

从pprint导入pprint
导入json
html_desc=“”
身体{
边框样式:实心;
边框宽度:5px;
边框颜色:绿色;
边界半径:5px;
边界间距:30px;
背景色:#FFFFC2;
垫底:5px;
字体大小:25px;
}
李{
颜色:#F7270F;
字体大小:粗体;
}
2018年1月8日一周的拍卖
您正在对以下项目进行投标:

  • 这是待售商品
    • 除非另有说明,否则包装条件为全新。请仔细阅读图片,如果您有任何关于特定内容的问题,请询问

      装运:装运将根据买方所在地进行计算。不收取保险费。除非价格超过50美元,否则卡将在8x5气泡邮递器中邮寄,并以头等邮件方式寄送,此时将优先寄送,买方不承担任何额外费用。如果您赢得多次拍卖,请等待发票发送

      """ pprint(json.dumps({html_desc:“Some Value”}))
from pprint import pprint
import json

html_desc = """<head>
<style>
body {
    border-style: solid;
    border-width: 5px;
    border-color: green;
    border-radius: 5px;
    border-spacing: 30px;
    background-color: #FFFFC2;
    padding-bottom: 5px;
    font-size: 25px;
}

li {
    color: #F7270F;
    font-weight: bold;
}
</style>
</head>
<body>
<div style="margin-bottom: 5px; margin-top: 5px; margin-left: 10px; margin-right: 10px;">
<h1 align="center">Auctions for Week of 08-01-2018</h1>
<p>You are bidding on the following item:</p>
<ul><li>This is the item for sale</li></ul>
<p>Condition is pack fresh unless otherwise indicated. Please review the pictures carefully and if you have any questions about something specific, ask.</p>
<p><b>Shipping:</b> Shipping will be calculated based on buyer location. No premiums are charged. Cards are mailed in an 8x5 bubble mailer and shipped First Class mail unless the price exceeds $50, at which point they will be shipped Priority at no additional cost to the buyer. If you win multiple auctions, please wait for an invoice to be sent.</p>
</div>
</body>"""

pprint(json.dumps({html_desc: "Some Value"}))