I'm trying to open a file in Python, but I got an error, and in the beginning of the string I got a /u202a
character... Does anyone know how to remove it?
def carregar_uml(arquivo, variaveis):
cadastro_uml = {}
id_uml = 0
for i in open(arquivo):
linha = i.split(",")
carregar_uml("H:\\7 - Script\\teste.csv", variaveis)
OSError: [Errno 22] Invalid argument: '\u202aH:\7 - Script\teste.csv'
use small letter when you write your hard-disk-drive name! not big letter!
ex) H: -> error ex) h: -> not error
Or you can slice out that character
When you initially created your .py file, your text editor introduced a non-printing character.
Consider this line:
Let's carefully select the string, including the quotes, and copy-paste it into an interactive Python session:
As you can see, there is a character with codepoint U-202A immediately before the
H
.As someone else pointed out, the character at codepoint U-202A is
LEFT-TO-RIGHT EMBEDDING
. Returning to our Python session:This further confirms that the first character in your string is not
H
, but the non-printingLEFT-TO-RIGHT EMBEDDING
character.I don't know what text editor you used to create your program. Even if I knew, I'm probably not an expert in that editor. Regardless, some text editor that you used inserted, unbeknownst to you, U+202A.
One solution is to use a text editor that won't insert that character, and/or will highlight non-printing characters. For example, in
vim
that line appears like so:Using such an editor, simply delete the character between
"
andH
.Even though this line is visually identical to your original line, I have deleted the offending character. Using this line will avoid the
OSError
that you report.try strip(),
The problem is the directory path of the file is not read properly. Use raw strings to pass it as argument and it should work.
you can use this sample code to remove u202a from file path
if i try to do this it gives me a OSError and In detail
but if i do that like this
Its working for me