Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python中的默认程序打开文件_Python - Fatal编程技术网

如何使用python中的默认程序打开文件

如何使用python中的默认程序打开文件,python,Python,如何从python打开文件?不使用open()函数进行读写,我的意思是模拟用户双击文件。因此,如果我打开file1.jpg,我希望它使用默认的图像程序打开 感谢windows上的,如果您通过win32 shell执行,就会出现这种行为。一种简单的方法是使用子流程模块: import subprocess as subp subp.call('file1.jpg', shell=True) 在linux中,您可以使用xdg open如下所示: from subprocess import cal

如何从python打开文件?不使用open()函数进行读写,我的意思是模拟用户双击文件。因此,如果我打开file1.jpg,我希望它使用默认的图像程序打开


感谢windows上的,如果您通过win32 shell执行,就会出现这种行为。一种简单的方法是使用子流程模块:

import subprocess as subp
subp.call('file1.jpg', shell=True)

在linux中,您可以使用xdg open如下所示:

from subprocess import call
call(['xdg-open','filename'])

你应该导入操作系统,并使用一些合适的工具。。。像xdg开放。。。i、 例如.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu