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

2024-06-26 14:46:05 发布

您现在位置:Python中文网/ 问答频道 /正文

脚本从上一个网页接收两个变量。根据这些变量,代码确定需要哪些图像。它将这些图像发送到一个临时文件夹,将该文件夹拉上拉链,并将其放置在一个输出文件夹中以便拾取。这就是事情发展的方向。我正在尝试允许网页提供一个按钮供用户点击并下载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)

最后一行指出问题出在哪里。Firebug表示链接是

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

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


Tags: 文件thepath图像脚本文件夹网页output
2条回答

os.rename方法不返回任何值。你可以看到官方文件here。它将文件或目录src重命名为dst。可能会引发一些异常。但什么也不回

^{}不返回任何内容,这意味着movedZip变成None

以下是您可能想要做的:

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

相关问题 更多 >