In the chapter “decision tree” of “machine learning in action”, the error typeerror: write() argument must be STR, not bytes is first prompted in the stored procedure of learning decision tree. The error message is that the parameter of write() function must be STR, not byte. I don’t understand. Look at the source code. There is an error. There is an error in compiling the sentence pickle. Dump (inputtree, FW). Let’s first look at the usage of pickle. Dump()
From the penultimate sentence, we can see that our problem lies in the variable FW, that is, the statement FW = open (file name, ‘W’). That is to say, the type of the variable FW should be bytes, so you can change ‘W’ to ‘WB’ and compile it successfully after modification. The same principle prompts Unicode decodeerror: ‘GBK’ codec can’t decode byte 0x80 in position 0: illegal multibyte sequence error, because the previously saved TXT file is written in binary, so binary should also be used when reading, Fr = open (filename) in the read file should be changed to fr = open (filename, ‘RB’). OK, problem solved! Under the test:
success!
Read More:
- Python PIP TypeError: expected str, bytes or os.PathLike object, not int
- [Solved] Python3.9 Pycropto RSA Error: TypeError: can’t concat str to bytes
- [Solved] python-sutime Error: the JSON object must be str, bytes or bytearray, not ‘java.lang.String‘
- [Solved] wsgiref make_server Error: AssertionError: write() argument must be a bytes instance
- Typeerror in Python regular expression: expected string or bytes like object
- [Solved] TypeError: Object of type ‘bytes’ is not JSON serializable
- Windows10 DOTA_devkit Error: TypeError: ‘>=‘ not supported between instances of ‘NoneType‘ and ‘str‘
- Python TypeError: Unrecognized value type: <class ‘str‘>dateutil.parser._parser.ParserError: Unknow
- [Solved] pycocotools Install Error: ERROR: Error expected str, bytes or os.PathLike object, not NoneType while executing
- Python Run Error: TypeError: hog() got an unexpected keyword argument ‘visualise‘”
- [Solved] Python Error: positional argument follows keyword argument
- [Solved] TypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
- [Solved] TypeError: xx takes 1 positional argument but 4 were given
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- Python: ___ () vs ___ str__()
- [Solved] RuntimeError: unexpected EOF, expected 73963 more bytes. The file might be corrupted.
- [Solved] TypeError: __init__() missing 1 required positional argument: ‘on_delete’
- Python Error: SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3:
- [Solved] Jupyter notebook: TypeError: __init__() got an unexpected keyword argument ‘io_loop’
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable