1

我搜索了高低,但正在努力使用以下代码。在底部的 for 循环中,我需要遍历多维列表的第一个元素中的名称。我对 Python 很陌生,所以请原谅我的无知。

for file in files: # loop thru each recording
  file_with_path = recording_fullpath + "/" + file  #construct full file path
  file_mtime = modification_date(file_with_path)  # obtain file mod date
  if file_mtime >= start_date and file_mtime <= end_date:
#print file + " is within the time range " + str(file_mtime)
archive_list[count].append (file_with_path)
archive_list[count].append (recording_subdir) # append filename with path to list
archive_list.append([])
count =+ 1

tarname = tar_path + "/" + client_id + "_" + dt.datetime.now().strftime("%Y%m%d_%H%M%S") + ".tar.gz"
print tarname
tar = tarfile.open (tarname, "w:gz")
for name in archive_list[][]:
  print "Adding %s" % (name)
  tar.add(name, arcname=client_id)
tar.close()

当我只使用单个元素数组但无法计算出包含第二列的语法时,此代码有效。

4

1 回答 1

1
tarname = tar_path + "/" + client_id + "_" + dt.datetime.now().strftime("%Y%m%d_%H%M%S") + ".tar.gz"
print tarname
tar = tarfile.open (tarname, "w:gz")
for name, dir in archive_list:
  print "Adding %s" % (name)
  tar.add(name, arcname=client_id)
tar.close()

这将遍历列表,将每个包含两个元素的子列表解压缩为两个变量,name并且dir.

于 2012-12-20T12:13:32.470 回答