Python:属性错误:'str'对象没有属性'readlines'



我正在尝试从mobileBuildSettings复制文本并使用它来替换abproject中的文本。我收到以下错误,但我不明白。

AttributeError: 'str' object has no attribute 'readlines'

下面是我的代码:

with open("C:/abproject.build", "r+") as script, open ("C:/tempfile.build","w+") as newscript:
abproject = ("C:/abproject.build")
for line in abproject.readlines():
    if line == "@AppIdentifier@" :
        newabproject.write('"' + "AppIdentifier : " + '"' + appIdentifier.get() + '"' + "n")
    else:
        newabproject.write(line)
abproject.close()
newabproject.close()
os.remove("abproject.txt")
os.remove("tempfile.buil","abproject.txt")

为了给jill1993的问题一个好的答案,并采取摩西·科勒多耶的答案:

abproject = ("C:/abproject.build")

abproject是一个字符串对象。此外,你写:

with open("C:/abproject.build", "r+") as script

所以如果你想解决你的脚本错误,你必须写:

with open("C:/abproject.build", "r+") as script, open ("C:/tempfile.build","w+") as newscript:
abproject = ("C:/abproject.build")
for line in script.readlines():
    if line == "@AppIdentifier@" :
        newscript.write('"' + "AppIdentifier : " + '"' + appIdentifier.get() + '"' + "n")
    else:
        newscript.write(line)
script.close()
newscript.close()
os.remove("abproject.txt")
os.remove("tempfile.buil","abproject.txt")

您的脚本应该可以;)

我改变了:

for line in abproject.readlines():

自:

for line in script.readlines():

相关内容

  • 没有找到相关文章

最新更新