字符串替换不适用于html插入

时间:2014-04-23 16:29:23

标签: python html

该脚本从前一个网页接收两个变量。从这些变量中,代码确定所需的图像。它将这些图像发送到临时文件夹,拉上该文件夹并将其放在输出文件夹中以便拾取。事情向南发展的地方。我试图让网页提供一个按钮供用户点击并下载zip文件。因为zip文件的名称需要根据脚本收到的变量进行更改,所以我不能只是创建一个zip文件的通用链接。

import arcpy, sys, shutil, os
path = "C:/output/exportedData/raw/"
pathZip = "C:/output/exportedData/zip/"

#First arg is the mxd base filename which is the same as the geodatabase name
geodatabaseName = "C:/output/" + sys.argv[1] + ".gdb"

#this is where the images are determined and sent to a folder

zipFileName = sys.argv[1]
zipFile = shutil.make_archive(path + zipFileName,"zip")
movedZip = os.rename(zipFile, pathZip + zipFileName + ".zip")
shutil.rmtree(path + zipFileName)
print """<h3><a href="{}">Download zip file</a></h3>""".format(movedZip)

最后一行表示问题的来源.Wirebug表示链接是

<a href="None">Download zip file</a>

在这种情况下字符串替换不起作用,我不知道为什么。如果您有任何帮助,请提前感谢您。

2 个答案:

答案 0 :(得分:2)

os.rename()没有返回任何内容,这意味着movedZip变为None

以下是您可能想做的事情:

movedZip = pathZip + zipFileName + ".zip"
os.rename(zipFile, movedZip)

答案 1 :(得分:0)

os.rename方法不返回任何值。你可以看到官方文件here。它将文件或目录src重命名为dst。可能会抛出一些异常。但是不会返回任何东西。