gpt4 book ai didi

python - 分区和 rpartiton 出现 TypeError : 'builtin_function_or_method' object has no attribute '__getitem__'

转载 作者:行者123 更新时间:2023-12-01 05:34:09 26 4
gpt4 key购买 nike

当我尝试运行脚本时收到此错误。

TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

这是脚本:

containerFile = open((tmpImageDirectory+"container.rvbr"), "r")
containedString = containerFile.read()
containerFile.close()
containedFiles = containedString .partition[","]

container.rvbr 包含一个带有多个逗号的字符串。如果执行这个str(conatinedString)我明白了<type 'str'> ,所以它是一个字符串。我想知道是否有人可以解释这一点。

最佳答案

使用括号而不是方括号来调用方法:

containedFiles = containedArray.partition(",")

此外,您可能想要进行 split 而不是 partition:partition 会将逗号保留在结果元组中,即使这些逗号实际上不是文件:

"hello,world".partition(",")
# ('hello', ',', 'world')
"hello,world".split(",")
# ['hello', 'world']

关于python - 分区和 rpartiton 出现 TypeError : 'builtin_function_or_method' object has no attribute '__getitem__' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19525087/

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