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
There are 2 best solutions below
Related Questions in WINDOWS
- Get Maximum Log Size
- Debugging Windows Services while starting
- Possible consequences of duplicate ProgId for different classes
- How to chain BCryptEncrypt and BCryptDecrypt calls using AES in GCM mode?
- mingw-64 conflicting declarations when cross-compiling
- I run an EXE program from a Windows Service but I can't see form C#?
- Why is PowerShell "not recognized" when installing Chocolatey?
- How to check if Windows device is phone or tablet/pc?
- How to add directories to Cygwin gcc default search path
- Can't install anything with pip2 on Windows 7 due to UnicodeDecodeError
- Active directory and linux nslcd binding without extending the AD schema
- How To Prevent Over Scrolling in Scroll Viewer Windows Phone 8.1
- Unicode error from pip install
- Where is the 'EnablePinning' property in the ribbon framework's recent items?
- How can I implement the same models and data across ASP.NET and Windows Apps
Related Questions in PYTHON-3.X
- Update a text file with ( new words+ \n ) after the words is appended into a list
- Kivy - Create new widget and set its position and size
- TypeError: encoding or errors without a string argument
- How to print varible name in python
- PyQt, Python 3: Lambda slot assigning signal argument to a variable?
- How to write data to stdin of the first process in a Python shell pipeline?
- pygame.draw.circle, still draws a square
- Duplicate Frames Created When Calling a Function in a Tkinter Application
- Python TypeError: can only concatenate tuple (not "int") to tuple
- recursively editing member variable: All instances have same value
- missing 1 required positional argument: 'key'
- How do I fix this sorting error?
- Dictionary values missing
- Why does opening a file in two different encodings work as expected?
- Binary bit flip generator in python
Related Questions in PYTHON-3.5
- What's the difference between type hinting in 3.3 and 3.5?
- Can PySide be used with Anaconda Python 3.5?
- How to install OpenAI Universe without getting error code 1 on Windows?
- create a 3d list (list of list of lists) from a pandas dataframe
- Cleanup of iterators that have not been fully exhausted
- How to fix broken pipe error in python networking
- I am trying to run flask for a flaskr tutorial but I am getting an error
- How do I specify OrderedDict K,V types for Mypy type annotation?
- Cocos2D-Python to Android/iOS
- How can redirect the user to another window without having to make pop up 2 windows
- how to select radio button in twitter by selenium webdriver with python?
- python runtime type checking
- Passing a Queue to Dynamically connecting Processes
- python - BeautifulSoup and requests does not produce expected results with .findAll()
- Why is my character ignoring the clock tick when i add the background?
Related Questions in MBCS
- MBCS to UTF-8: How to encode in Python
- Does ANTLR for Java support MBCS?
- C++ Using std::string functions for MBCS and std::wstring functions for UTF-16
- How to convert UNICODE strings to MBCS in c#?
- How to work with substrings / delete character when content is mixed single and double byte?
- Under what circumstances would an EDIT control treat MBCS as UNICODE?
- How do I write MBCS files from a UNICODE application?
- Within Windows MBCS, what languages have 2 byte characters and what characters are they?
- MFC dialogs caption fails with Unicode
- MFC Multibyte Add-on for Visual Studio 2015 Express for Desktop
- How to know the preferred display width (in columns) of Unicode characters?
- Risks of running on single byte character app on a MBCS OS
- Logic behind converting a character to UTF-8
- Converting from Windows MBCS to UTF-8
- Read *.txt file with German text, show it in my GUI -- characters with umlauts not correct
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
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.