1
I have a Python program that asks the user for a file path and shows the contents of the file on the screen. The problem is that the code only works when I put the names of Windows folders in English.
For example:
>>> print(open('C:\\Usuários\\usuario\\Documentos\\Gamepobre.txt').read())
returns an error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Usuários\\usuario\\Documentos\\Gamepobre.txt'
But if I trade Users and Documents for Users and Documents:
>>> print(open('C:\\Users\\usuario\\Documents\\Gamepobre.txt').read())
It shows the contents on the screen as expected.
How will the program use user input, is there any way to convert the path in Portuguese to the English equivalent and avoid this error? I searched but I didn’t find anything that mentions it on the Internet.
I’m sorry if this is incredibly obvious. I’m just getting started. I’m also using Pycharm, if it helps.
It worked perfectly! is a much better solution. But just to top it off, there would be some way to translate the folder names of a string if I theoretically decided not to use this solution, or I would have to program everything by hand?
– Fupi
In fact I don’t even think that programming by hand is possible @Fupi - the
shell32.dll
can have any kind of programmed illusion, translations into any language or even other things. The only way to know how a folder will appear "illusorily" for the user who uses windows explorer is by asking for windows explorer itself, since it does not show the real names of the folders. The user is tricked into thinking that the folder has a name, when in fact it has another name. Imagine that your code is running in a Japanese windows - it would have all the translations of all the folders?– nosklo