简体   繁体   English

如何用Python打开文件名中的空格?

[英]How to open a file with Python with white spaces in the name?

I have files that cannot be renamed without white spaces (work files). 我有没有空格就不能重命名的文件(工作文件)。 The file name is Evo PROG6001 FSJD0250240 E.PART stored in a variable file . 文件名是Evo PROG6001 FSJD0250240 E.PART存储在变量file If I run os.system('start ' "'" + file + "'") it only recognizes the word Evo and returns Windows cannot find "Evo". Make sure you types the name correctly, and then try again 如果我运行os.system('start ' "'" + file + "'")它只能识别单词Evo并返回Windows cannot find "Evo". Make sure you types the name correctly, and then try again Windows cannot find "Evo". Make sure you types the name correctly, and then try again . Windows cannot find "Evo". Make sure you types the name correctly, and then try again The same thing occurs with os.system('start ' + file) . os.system('start ' + file)也会发生同样的事情。

Is there a way to do this? 有没有办法做到这一点?

I needed to use os.startfile() and also point it to the root directory, which I had stored previously. 我需要使用os.startfile()并将其指向我之前存储的根目录。

os.startfile(new_folder + '\\\\' + file) works os.startfile(new_folder + '\\\\' + file)有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM