Issue
hella.
seems to be a wrong path on my Python code. But I test again and again, the path and the file are good: c:\Folder1\bebe.txt
See the error OSError: [Errno 22] Invalid argument: 'c:\\Folder1\x08ebe.txt'
Python modify my path ??! Can you help me? Also, you have the entire code HERE:
Solution
Your problem is most likely this line:
file_path = 'C:\Something\booh'
In a Python string literal, backslashes are used to introduce special characters. For example \n
means a newline and \b
means a backspace. To actually get a backslash, you have to type \\
. A backslash followed by a character with no special meaning is left alone, so \S
actually means \S
(though relying on this is probably a bad idea).
You can either type your line like this
file_path = 'C:\\Something\\booh'
or use Pythons "raw string" syntax, which turns off the special meaning of backslashes, and type
file_path = r'C:\Something\booh'
Notice that when you do
s = '\\'
the string referred to by s
actually contains a single backslash. For example, len(s)
will be 1, and print(s)
will print a single backslash.
Answered By - Ture Pålsson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.