Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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 字符串替换不适用于html插入_Python_Html - Fatal编程技术网

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

Python 字符串替换不适用于html插入,python,html,Python,Html,脚本从上一个网页接收两个变量。根据这些变量,代码确定需要哪些图像。它将这些图像发送到一个临时文件夹,将该文件夹拉上拉链,并将其放置在一个输出文件夹中以便拾取。这就是事情发展的方向。我试图让网页提供一个按钮,让用户点击并下载zip文件。因为zip文件的名称需要根据脚本接收到的变量进行更改,所以我不能只创建到zip文件的通用链接 import arcpy, sys, shutil, os path = "C:/output/exportedData/raw/" pathZip = "C:/outpu

脚本从上一个网页接收两个变量。根据这些变量,代码确定需要哪些图像。它将这些图像发送到一个临时文件夹,将该文件夹拉上拉链,并将其放置在一个输出文件夹中以便拾取。这就是事情发展的方向。我试图让网页提供一个按钮,让用户点击并下载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)
导入arcpy、sys、shutil、os path=“C:/output/exportedData/raw/” pathZip=“C:/output/exportedData/zip/” #第一个参数是与地理数据库名称相同的mxd基本文件名 geodatabaseName=“C:/output/”+sys.argv[1]+“.gdb” #这是确定图像并将其发送到文件夹的位置 zipFileName=sys.argv[1] zipFile=shutil.make_存档(路径+zipFileName,“zip”) movedZip=os.rename(zipFile,pathZip+zipFileName+“.zip”) rmtree(路径+zipFileName) 打印格式(movedZip) 最后一行指出问题出在哪里。Firebug表示链接已建立

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

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

不返回任何内容,这意味着
movedZip
将变为
None

以下是您可能想要做的:

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

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

啊,很好。成功了。非常感谢。然而,现在当我点击链接时,它没有响应。当我将鼠标悬停在链接上时,显示的地址为“file:///C:output/exportedData/zip/zippedfile.zip". 我是否需要以某种方式修剪输入变量?@Iakona您需要的链接文本是什么?