问题
So I was running into a bit of a problem today with this bit of code:
os.system("C:\Program Files (x86)\DOSBox-0.72\dosbox.exe")
Upon execution I'd get this error message:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
I assumed it was something to do with either the white space or the brackets, so I did a bit of digging online and after countless of ineffective "solutions" involving escape characters, I ended up finding a rather strange solution; to surround the double quotes with another double and a single like so:
os.system('""C:\Program Files (x86)\DOSBox-0.72\dosbox.exe""')
I'm confused as to why this works, which I guess isn't very surprising given my lack of python knowledge. I was searching the internet to find out why this works, but to no avail.
So I guess the question is, why does adding those quotes solve the problem?
I'm very new to Python, and programming in general so I'd greatly appreciate any answer to be explained in layman terms.
Thanks in advance.
EDIT: I wouldn't say this question is a duplicate of the linked one, I was not after a solution to the problem, I already had one. I was curious as to why it worked, the logic behind it, so I could better understand the way python works.
来源:https://stackoverflow.com/questions/26153632/why-does-this-triple-quoting-solution-fix-path-error