Python_:TypeError: write() argument must be str, not int

Detailed map traversal, teach you to master the complex gremlin query debugging method>>>

Python_ Error: typeerror: write() argument must be STR, not int

When running the file write operation, an error is reported: typeerror: write() argument must be STR, not int

Upper Code:

fp = open("1023a.txt","w+")
l = [1023,1024,1025]
fp.writelines(l)
fp.seek(0,0)
fp.read()
fp.close()

The operation effect is as follows:

Cause analysis:
writelines() can pass in both a string and a character sequence, and write the character sequence to a file
note: writelines must pass in a character sequence, not a number sequence

It can be changed as follows:

fp = open("1023b.txt","w+")
l = ["1023","1024","1025"]
fp.writelines(l)
fp.seek(0,0)
fp.read()
fp.close()

The following results are:

Similar Posts: