如何在Python脚本

时间:2015-07-04 00:07:14

标签: python html

重新编辑问题:

所以目前我有

imagepath = os.join.path (currentdirectory, fruit, size, fruitproperty + ".html")

现在我想将此路径插入以下代码:

htmlfile.write('<a href = imagepath > '+fruitproperty+' </a><br>\n') 

所以我的问题是如何在其中插入imagepath?我尝试了各种方法,但没有工作。

1 个答案:

答案 0 :(得分:0)

您可以使用string.format,示例 -

imagepath = os.join.path (currentdirectory, fruit, size, fruitproperty + ".html")
htmlfile.write(('<a href = {imagepath} > '+fruitproperty+' </a><br>\n').format(imagepath = imagepath))

此处,imagepath(大括号)中的{}将替换为imagepath的值。