gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:57:18 36 4
gpt4 key购买 nike

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

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

最佳答案

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

以下是您可能想要执行的操作:

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

关于python - 字符串替换不适用于 html 插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23250220/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com