gpt4 book ai didi

python - 属性错误: 'ZipInfo' object has no attribute 'filemode'

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:25 25 4
gpt4 key购买 nike

如何访问zip文件的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'

最佳答案

文件属性存储在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

关于python - 属性错误: 'ZipInfo' object has no attribute 'filemode' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55165505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com