gpt4 book ai didi

python 'for key in' - 如何修复 'SyntaxError: invalid syntax'

转载 作者:太空宇宙 更新时间:2023-11-04 10:49:24 25 4
gpt4 key购买 nike

我正在尝试从 github ( https://github.com/danielfullmer/nzbfs ) 安装 (python setup.py install) 一些 python 包,但正在获取

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/nzbfs/fs.py', 135, 15, "            for key in ('st_atime', 'st_ctime', 'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid'):\n"))

怎么了?在 debian 上尝试过 python2.6 + 3.1,但总是卡在 for key ..

def getattr(self, path, fh=None):
st = os.lstat(self.db_root + path)

d = {
key: getattr(st, key)
for key in ('st_atime', 'st_ctime', 'st_gid', 'st_mode',
'st_mtime', 'st_nlink', 'st_size', 'st_uid')
}

if stat.S_ISREG(st.st_mode):
nzf_size = get_nzf_attr(self.db_root + path, 'size')
if nzf_size is not None:
d['st_size'] = nzf_size
nzf_mtime = get_nzf_attr(self.db_root + path, 'mtime')
if nzf_mtime is not None:
d['st_mtime'] = nzf_mtime
d['st_blocks'] = d['st_size'] / 512

return d

最佳答案

给出语法错误的行称为 dict comprehension ;这些已添加到 Python 2.7 和 3 的语言中。

此模块 Python 3 就绪;例如,它使用 ConfigParser 模块,在 Python 3 中已重命名为 configparser。您必须坚持使用 Python 2.7。

如果这对你来说是一个阻碍,你将不得不 raise an issue与开发人员一起,要求 Python 2.6 兼容性(实现起来并不难)。

关于python 'for key in' - 如何修复 'SyntaxError: invalid syntax',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14910051/

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