【发布时间】:2018-08-23 09:46:06
【问题描述】:
我正在尝试调用应用程序并将文本文件作为参数传递。文本文件有说明。我尝试在打开记事本时传递一个参数,但无法让它工作。这是我正在尝试的代码:
import os
os.startfile(r"C:\Windows\notepad.exe c:\cobra\advancecalendar.txt")
If I don't include the path to the second file it launches notepad, but with the file name included i get the following error:
RESTART: C:/Users/timbo/AppData/Local/Programs/Python/Python36-32/Open exe module.py
Traceback (most recent call last):
File "C:/Users/timbo/AppData/Local/Programs/Python/Python36-32/Open exe module.py", line 3, in <module>
os.startfile(r"C:\Windows\notepad.exe c:\cobra\advancecalendar.txt")
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Windows\\notepad.exe c:\\cobra\\advancecalendar.txt'
如何将参数传递给 startfile 以打开特定文件?当我尝试将两者都放在引号中时,它仍然出现错误。
【问题讨论】:
-
尝试多搜索一下,我想这个问题经常被问到。
-
只对文件使用
os.startfile(),不使用应用程序。 -
谢谢。我没有看到一个带参数的,但可能会缩小我的搜索范围会再次挖掘
标签: python exe parameter-expansion