问题
I am working on a little project in python for work.
It involves opening a file with the os.startfile()
And there in lies my problem :
the path to the file contains several numbers. And for some reason I don't understand this cause problems in locating the file.
Is there a work around for this?
Because I can't change the names of the directory or the file.
回答1:
The problem is that the \
character has a special meaning in python, e.g. \n
is a newline etc.
You can either do:
os.startfile(r"G:\EEGdatabase\6541455.docx")
Or:
os.startfile("G:\\EEGdatabase\\6541455.docx")
To solve the problem.
See https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals for details.
来源:https://stackoverflow.com/questions/43204473/os-startfile-path-in-python-with-numbers