0

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:

enter image description here

  • Ture Pålsson's answer is correct about the escaping of strings - please consult it for more – jrd1 Nov 19 '21 at 22:18
  • yes, the answer may be correct, but that did not solve the problem... –  Nov 20 '21 at 07:31

1 Answers1

1

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.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Ture Pålsson
  • 6,088
  • 2
  • 12
  • 15
  • the complete Python code is here: https://pastebin.com/yXfD1XK8 –  Nov 19 '21 at 08:40
  • 1
    try to change the line with path as follows: `file_path = "c:\\Folder1\bebe.txt'.replace('\', '\\')"` – Just Me Nov 22 '21 at 07:47