file - Python: AttributeError: 'str' object has no attribute 'readlines' -
i trying copy text mobilebuildsettings
, use replace text abproject
. getting following error , don't understand it.
attributeerror: 'str' object has no attribute 'readlines'
below code:
with open("c:/abproject.build", "r+") script, open ("c:/tempfile.build","w+") newscript: abproject = ("c:/abproject.build") 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")
in order give answer jill1993's question , take moseskoledoye's answer :
abproject = ("c:/abproject.build")
abproject
string object. furthermore, write :
with open("c:/abproject.build", "r+") script
so if want solve script error, have write :
with open("c:/abproject.build", "r+") script, open ("c:/tempfile.build","w+") newscript: abproject = ("c:/abproject.build") 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")
and script should work ;)
Comments
Post a Comment