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.