I am trying to create a duplicate file finder for Windows. My program works well in Linux. But it writes NUL characters to the log file in Windows. This is due to the MBCS default file system encoding of Windows, while the file system encoding in Linux is UTF-8. How can I convert MBCS to UTF-8 to avoid this error?
MBCS to UTF-8: How to encode in Python
7.8k Views Asked by achint chaudhary At
2
Tell Python to use UTF-8 on the log file. In Python 3 you do this by:
If you want to convert an MBCS string to UTF-8 you can switch string encodings:
Use
filename.encode(sys.getdefaultencoding())...
to make the code work on Linux, as well.