SoFunction
Updated on 2024-11-16

The ultimate solution for handling Chinese paths based on python.

1 、Supposedly python3 doesn't have this problem anymore

2 、u 'string' represents unicode format data, the path is best written in this format, do not directly with the string 'string' of this kind of data, after adding type is str, so there will be decoding errors.

Don't add directly to the string 'string'.

Don't add directly to the string 'string'.

Don't add directly to the string 'string'.

The unicode type should not be added directly to the string 'string'.

Say it four times.

3 、Some of the way to read is to read str type of path, not unicode type of path, then we put this ('utf-8') on it, save to txt is also handled in this way, because save to txt, the Chinese also have to be converted to utf-8 format string.

4 、.decode('utf-8'), is only the original utf-8 character encoding type into unicode, that is, unified. encode('utf-8') is to decode unicode into utf-8 type, Chinese data need to be decoded into utf-8 to see Oh!

5 、Read from text and then write to csv, .decode("gb2312").encode("utf-8")

This is based on python processing Chinese path to the ultimate solution is all I have shared with you, I hope to give you a reference, and I hope you support me more.