This question already has answers here:
Open document with default OS application in Python, both in Windows and Mac OS
                                
                                    (13个回答)
                                
                        
                                3年前关闭。
            
                    
我想让我的python程序在Windows中执行文件。这意味着如果我尝试执行.txt文件,它将使用默认的.txt查看器打开。那可能吗?

我尝试了subprocess.call,但得到了WindowsError: [Error 193] %1 is not a valid Win32 application。我要运行的文件是.png文件。

最佳答案

os.startfile("myText.txt") #open text editor
os.startfile("myText.pdf") #open in pdf viewer
os.startfile("myText.html") #open in webbrowser


你应该怎么做

然而

os.startfile("my_prog.py")


可能是个坏主意,因为无法知道是否将python设置为默认打开* .py或是否将texteditor或ide设置为默认打开* .py

关于python - 在Windows中使用Python执行文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36779116/

10-12 16:20
查看更多