so I have just wanted to create a simple string but for some reason I get an error:
file_path = r"C:\Users\hadad\Desktop\webroot\imgs\"
whats wrong with that?
so I have just wanted to create a simple string but for some reason I get an error:
file_path = r"C:\Users\hadad\Desktop\webroot\imgs\"
whats wrong with that?
Remove the leading \ to avoid to escape ":
file_path = r"C:\Users\hadad\Desktop\webroot\imgs"
# HERE ---^
Or use:
file_path = "C:\\Users\\hadad\\Desktop\\webroot\\imgs\\"
file_path = "C:/Users/hadad/Desktop/webroot/imgs/"
Interestingly, you cannot do that with a raw string:
Even in a raw literal, quotes can be escaped with a backslash, but the backslash remains in the result; for example,
r"\""is a valid string literal consisting of two characters: a backslash and a double quote;r"\"is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw literal cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the literal, not as a line continuation.https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
Instead, you might want to resort to the plain string literal:
file_path = 'C:\\Users\\hadad\\Desktop\\webroot\\imgs\\'