我有下面的代码,它可以在“我的文件夹”中设置路径,并压缩与shp相关的所有文件类型(我没有编写它,还有其他一些聪明的星星之火)。然而,我想要聪明,循环一个包含大量路径列表的文本文件。我必须理解循环遍历txt文件并打印出文件路径列表的概念,但我不确定如何将两者连接起来。任何帮助都会很好。
是的
简单回路
items = 'shp_folders.txt'
with open (items) as f:
for line in f:
print(line)
f.seek(0)
for line in f:
无论出于什么原因,我都无法打开或访问此子目录中的文件。我需要能够打开和读取压缩文件夹的子目录中的文件。这是我的代码。 import zipfile
import os
for root, dirs, files in os.walk('Z:\\STAR'):
for name in files:
if '.zip' in name:
try:
zipt=zipfile.ZipFile(os.path.join(root,name),'r')
我正在尝试将以前为Python 2.7编写的代码重写为Python 3.4。我在下面代码中的行zipfile.BadZipFile: File is not a zip file中得到了错误zipfile = ZipFile(StringIO(zipdata))。
import csv
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import pandas as pd
import os
from zipfile import ZipFile
from pprint
关门了。这个问题是not reproducible or was caused by typos.它目前不接受答案。 想要改进这个问题吗?更新问题,使其成为on-topic主题堆栈溢出。 5天前就关门了。 Improve this question 我有一些代码,可以将文件夹中的特定扩展文件写入zip文件。尽管我继续遇到一个错误。我从几个不同的来源提取了这段代码。我能得到一些帮助吗? ext = [".shp", ".shx", ".prj", ".cpg", ".dbf
我有一个包含许多and文件的文件夹,这些and文件中的大多数包含shapefile,而其中一些包含包含shapefile的and文件的子文件夹。我试图将所有内容提取到一个主文件夹wihtout中,保持任何文件夹结构。这就是我现在的处境;
import os, zipfile
def getListOfFiles(dirName):
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allF
我试图通过下面的代码来处理HTTP错误。但是,我发现每当我调用message来查看异常处理是否有效时,我都会在行df = update(currency)[1]中得到错误'NoneType' object has no attribute '__getitem__',尽管update返回NoneType时试图处理该情况。
import csv
from io import BytesIO
import pandas as pd
import os
from zipfile import ZipFile
from pprint import pprint, pfo
我试图使用Python中的以下命令序列替换Word文件中的子字符串。代码本身工作非常好--即使使用完全相同的Word文件,但是当将其嵌入到更大规模的项目结构中时,它会在这个位置抛出一个错误。我不知道是什么原因造成的,因为它似乎与代码无关,而且对我来说似乎是无可指责的。
附带注意:我知道是什么导致了错误,它是Word文件中的一个德语“ü”,但是它是必需的,如果代码独立工作,删除它似乎不是正确的解决方案。
#foo.py
from bar import make_wordm
def main(uuid):
with open('foo.docm', 'w+'
我有一个10 in压缩压缩的csv文件。下面是我试图读取csv文件的代码。但是,此方法引发属性错误。请推荐其他快速阅读大csv的方法。
import zipfile as zp
import dask.dataframe as dd
file_dir = 'W:\\XYZ\\salaryofemployees.CSV.ZIP'
csv_file = "salaryofemployees.CSV"
with zp.ZipFile(file_dir) as z:
with z.open(csv_file) as f:
dask_df = dd
您好,我的错误是在生成压缩文件时产生的。你能告诉我该怎么做吗?
main.py", line 2289, in get
buf=zipf.read(2048)
NameError: global name 'zipf' is not defined
完整代码如下:
def addFile(self,zipstream,url,fname):
# get the contents
result = urlfetch.fetch(url)
# store the contents in a stream
每当我试图从作为守护进程运行的python脚本中运行解压缩命令时,我就会收到一个错误。
指挥:
解压缩abcd.zip > /dev/null
错误
End-of-central-directory signature not found$ a zip file, or it
constitutes one disk of a multi-part archive. In the latter case
the central directory and zipfile comment will be found on the last
disk(s) of this arc
我使用System.IO.Compression.ZipFile提取压缩文件,但是压缩文件结束时.exe,我可以右击并解压,如果我自己但是我需要在c#中这样做。
现在我发现了这个错误
zip file end of central directory record could not be found
我如何提取这个文件?
我的代码
string zipPath = DeffDownFolder + @"\archive.exe";
string extractPath = strFilePath + "\\" + AccountNumber;
System.
在不解压缩压缩文件的情况下,可以从zip文件读取文件吗?我想在备忘录行中从压缩文件(作为android资产)读取文本文件。
ZipFile := TZipFile.Create; //Zipfile: TZipFile
try
ZipFile.Open('C:\Path\to\file.zip', zmRead);
for I := 0 to ZipFile.FileCount - 1 do
begin
if ZipFile.FileNames[I]='A1.txt' then //S: string
//My problem is here ? How