Python,open.system函数-文件名中有空格时出错

Python,open.system函数-文件名中有空格时出错,python,Python,我正试图从系统文件夹中打开一个文件 import os Folder = "C:\\Users\\kasan\\Videos" File = Folder+'\\'+os.listdir(Folder)[0] print(File) #C:\Users\kasan\Videos\big bang theoryE12S6.mp4 os.startfile(Folder)#open the folder os.system(File) #should open the mp4 file 但是o

我正试图从系统文件夹中打开一个文件

import os

Folder = "C:\\Users\\kasan\\Videos"
File = Folder+'\\'+os.listdir(Folder)[0]

print(File) #C:\Users\kasan\Videos\big bang theoryE12S6.mp4
os.startfile(Folder)#open the folder
os.system(File) #should open the mp4 file
但是os.system()给了我一个错误。下面是错误

'C:\Users\kasan\Videos\big' is not recognized as an internal or external command,
operable program or batch file.
与其读《大爆炸理论》12s6.mp4,不如只读第一部分。
如何克服这个问题?提前感谢您的帮助。

您可以将文件名放在双引号中以保留空白:

os.system('"%s"' % File)

为什么要使用
os.system
?正如我在脚本注释中提到的。。打开一个文件。啊!!好的旧字符串格式。。。我怎么会忘了这件事。。无论如何,谢谢!!