Issue
hello everyone I have a problem with a python 2.X script that I would like to run in 3X here is the error message can you help me
outfile.write(fixed.encode,"(utf-8)")
TypeError: write() takes exactly one argument (2 given)
Edit:
#Write the converted program in this folder:
print ("\n--Converted to TI-Basic code:--")
print (fixed)
print ("")
print ("Making output files: "+outname+".tib, "+outname+".8xp ...")
outfile=open(outname+".tib","w")
outfile.write(fixed.encode("utf-8"))
outfile.close()
the code and the new errore message : line 68, in main outfile.write(fixed.encode("utf-8")) TypeError: write() argument must be str, not bytes
Solution
The Error "TypeError: write() argument must be str, not bytes" is because you are trying to write in byte data but you didn't specified opened the file in byte mode. If you want to write string into a file use with
statement
with open(outname+".tib","wb") as outfile:
outfile.write(fixed.encode("utf-8"))
If the fixed variable is str
type then you can avoid the encode('utf-8')
from the above code then the mode should be just w
Answered By - mohammed wazeem
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.