Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.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 在jar目录中查找csv文件中的内容_Python_Zipfile - Fatal编程技术网

Python 在jar目录中查找csv文件中的内容

Python 在jar目录中查找csv文件中的内容,python,zipfile,Python,Zipfile,我试图使用ZipFile查看jar目录,并在该目录中的csv文件中查找特定内容。到目前为止,我已经: def check_variable(jar_path): with zipfile.ZipFile(jar_path, 'r') as zipf: ret_reader = csv.reader(zipf) for row in ret_reader: if row[0] == 'Variable Label':

我试图使用ZipFile查看jar目录,并在该目录中的csv文件中查找特定内容。到目前为止,我已经:

def check_variable(jar_path):
    with zipfile.ZipFile(jar_path, 'r') as zipf:
        ret_reader = csv.reader(zipf)
        for row in ret_reader:
            if row[0] == 'Variable Label':
                return row[1]
    raise OutputError('Variable Label not found in file %s!' % ret_file_name)
这似乎不起作用。谁能给我指一下正确的方向吗?谢谢大家!

zipfile.zipfile(jar_路径,'r')
返回一个对象。因此,您需要将csv文件保存在zip文件中

with zipfile.ZipFile(jar_path, 'r') as zipf:
    with zipf.open(csv_path, 'r') as csvpf:

你能编辑这个问题来添加回溯吗?除了@yao99的评论,还有-当事情没有按预期进行时,你可能需要检查变量包含什么