I'm trying to run os.stat
in pool
for list of files but as result receive just nested list of files statistics:
我在试着运行操作系统。在poolfor文件列表中,但结果只接收到的文件统计信息列表:
list_of_files = ['file1.txt','file2.txt','file3.txt']
p = Pool(4)
list_of_stats = p.map(os.stat, list_of_files)
list_of_fies
contains the next value: nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=8905L, st_atime=1499725858L, st_mtime=1416573654L, st_ctime=1445009618L)...
list_of_fies包含下一个值:nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=8905L, st_atime=1499725858L, st_mtime=1416573654L, st_ctime=1445009618L)…
my question is: what is the simplest way to get the file name + statistics related to this files in list/dict?
我的问题是:最简单的方法是如何获取与此文件相关的文件名称和统计信息?
for instance dict: {'file1.txt': [st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=8905L, st_atime=1499725858L,...]}
例如dict:{ file1。txt: [st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=8905L, st_atime=1499725858L,…]}
1 个解决方案
#1
0
I've found the solution with using the code similar to below:
我已经找到了使用类似以下代码的解决方案:
list_of_files = [name1, name2, name3, name4]
def file_stat(file_path):
return (file_path, os.stat(file_path))
if __name__ == "__main__":
p = Pool(2)
list_of_stats = p.map(file_stat, list_of_files)
print(type(list_of_stats))
print(list_of_stats)
output:
输出:
<type 'list'>
[(u'\\path\to\file\name1.xml', nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=8905L, st_atime=1501540255L, st_mtime=1416573654L, st_ctime=1445009618L)), (u'\\path\to\file\name2.xml', nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=47000L, st_atime=1501540327L, st_mtime=1475583701L, st_ctime=1445009618L)), ... ]
#1
0
I've found the solution with using the code similar to below:
我已经找到了使用类似以下代码的解决方案:
list_of_files = [name1, name2, name3, name4]
def file_stat(file_path):
return (file_path, os.stat(file_path))
if __name__ == "__main__":
p = Pool(2)
list_of_stats = p.map(file_stat, list_of_files)
print(type(list_of_stats))
print(list_of_stats)
output:
输出:
<type 'list'>
[(u'\\path\to\file\name1.xml', nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=8905L, st_atime=1501540255L, st_mtime=1416573654L, st_ctime=1445009618L)), (u'\\path\to\file\name2.xml', nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=47000L, st_atime=1501540327L, st_mtime=1475583701L, st_ctime=1445009618L)), ... ]