V. Zalama
V. Zalama

Reputation: 11

Python special characters encoding problems in PATH

Given this simple code, I receive faulty paths if the userfolder contains any special characters. For example the returned path is expected to be "C:\Users\Aoë\", but the ë is instead shown as a ‰ or a \u2030 depending on what is done with encoding. This then messes up the rest of my code because of attempts to write to nonexistent paths.

I ran into this problem trying to run kivy, but it seems to be happening globally.

from pathlib import Path
home = str(Path.home())
print(home)

I've spent quite some time, but haven't been able to reach a solution. This is with the latest python, x64 on windows with eclipse. No matter what I do, I cannot get python to handle special characters properly.

Upvotes: 1

Views: 773

Answers (1)

v.coder
v.coder

Reputation: 1932

Try 'r' tag at the beginning, it ignores the special characters:

home = r'%s'%str(Path.home()) 

Upvotes: 1

Related Questions