Below for everyone to share a discussion of Python in Windows file path problem, has a good reference value, I hope to be helpful to everyone. Come and see it together.
When you use Python to open a file by using the open () function, passing an absolute path to open (), you find that the contents of the path parameter differ from the imaginary:
A conflict may occur because the path delimiter for Windows uses a backslash \, which is just a good escape character
# Error Demonstration: Backslash appears to be interpreted as escape character instead of delimited character path = ' F:\Python\test.txt ' ' path = ' ' F:\\python\test.txt ' ' "" "" "" "" "" "" Path = ' F:\Python\\test.txt ' ' path = ' f:\\python\\test.txt ' ' path = ' ' F:\Python\\test.txt ' ' The last backslash of an absolute path uses a double backslash when it is normal ' ' ' because the last backslash can be an escape effect with the character t next to it
conclusion: when using an absolute path, be aware that the backslash used in the absolute path and the character immediately following it will not form an escape effect, and if it produces an escape effect, such as \ t \ r, and so on, you must use a double backslash to cancel the escape effect of the SLR slash. If an escape character is generated, an open () hint "Invalid arguments" will appear.