如何访问zipfile的filemode属性?
>>> info = zin.infolist()[1]
>>> info
<ZipInfo filename='test_dir/' filemode='drwxr-xr-x' external_attr=0x10>
>>> info.filename
'test_dir/'
>>> info.external_attr
1106051088
>>> info.filemode
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ZipInfo' object has no attribute 'filemode'
答案 0 :(得分:0)
文件属性存储在external_attr
的高位(低16位上方):
oct(1106051088 >> 16)
#'0o40755'
要检查特定权限,请使用模块stat
中的功能,例如:
stat.S_ISDIR(1106051088 >> 16)
# True, a directory
stat.S_IRUSR & (1106051088>>16)
# 256, user-readable
stat.S_IWGRP&(1106051088>>16)
# 0, not group-writable