When writing to a file, an error is reported: TypeError: write() argument must be str, not list
Reason: The content written by python should be of string type
Code.
fp = open(“a.txt”,”w”)
fp.write([1,2,3])
fp.close()
>>> fp = open("a.txt","w")
>>> fp.write([1,2,3])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: write() argument must be str, not list
>>> fp.close()
If the writing content is string type, OK
fp = open("a.txt","w")
fp.write('[1,2,3]')#Processing file contents to string type
fp.close()
Similar Posts:
- Python3: list dict set [UNK]unhashable type
- TypeError: list indices must be integers or slices, not tuple
- Python: ValueError: too many values to unpack
- [Solved] Python TypeError: sequence item 0: expected str instance, int found
- Python_:TypeError: write() argument must be str, not int
- Error about exchange mode type in rabbitmq [How to Solve]
- How to Solve Python TypeError: ‘list’ object is not callable
- Python TypeError: file must have ‘read’ and ‘readline’ attributes
- Python OpenCV TypeError: integer argument expected, got float
- Python TypeError: unbound method a() must be called with A instance as first argument (go…