This example?
The error happens in the function print. You can use a kind of hack to ship aroud this:
It can also causes trouble with other Applications like an file explorer, backup tools etc...
BTW: The use of pathlib.Path has the same problem. The representation of the Path is ok
To print the representation of something:
# !/usr/bin/python3 import os os.chdir("d:\\tmp") for root, dirs, files in os.walk(".", topdown = False): for name in files: print(os.path.join(root, name)) for name in dirs: print(os.path.join(root, name))I guess a filname or path on your filesystem is using invalid unicode.
The error happens in the function print. You can use a kind of hack to ship aroud this:
def encdec_hack(s): return s.encode("utf8", errors="ignore").decode() for root, dirs, files in os.walk("."): for f in files: try: print("File [ OK ]:", f) except UnicodeEncodeError: print() print("File [ ERR ]:", encdec_hack(f))The best solution is: Fix your filesystem. Delete or rename the files with broken encoding.
It can also causes trouble with other Applications like an file explorer, backup tools etc...
BTW: The use of pathlib.Path has the same problem. The representation of the Path is ok
To print the representation of something:
print(repr(something))
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!