Open windows photo gallery from python

Mor*_*ive 1 python windows

I want the end of a python script to open windows photo gallery from python

I try:

os.system("C:\\Program Files (x86)\\Windows Live\\Photo Gallery\\WLXPhotoGallery.exe");
Run Code Online (Sandbox Code Playgroud)

I get:

os.system("C:\\Program Files (x86)\\Windows Live\\Photo Gallery\\WLXPhotoGallery.exe");
Run Code Online (Sandbox Code Playgroud)

any ideas how to get this one sorted?

ins*_*get 5

正如 Martijn Pieters 指出的那样,您确实应该使用subprocess. 但是,如果您真的很好奇为什么您的调用不起作用,那是因为调用os.system("C:\\Program Files (x86)\\Windows Live\\Photo Gallery\\WLXPhotoGallery.exe");相当于在命令行上键入:C:\Program Files (x86)\Windows Live\Photo Gallery\WLXPhotoGallery.exe
看到文件路径中的那些空格了吗?Windows shell 将每个空格分隔的字符串视为单独的命令/参数。C:\Program因此,它尝试使用参数Files, (x86)\Windows, Live\Photo,来执行程序Gallery\WLXPhotoGallery.exe。当然,由于您的计算机上没有程序C:\Program,所以这很奇怪。

如果出于某种原因,您确实想要使用os.system,您应该考虑如何在命令行本身上执行该命令。要在命令行上执行此操作,您需要键入"C:\Program Files (x86)\Windows Live\Photo Gallery\WLXPhotoGallery.exe"(引号转义空格)。为了将其转化为您的os.system调用,您应该执行以下操作:

os.system('"C:\\Program Files (x86)\\Windows Live\\Photo Gallery\\WLXPhotoGallery.exe"');
Run Code Online (Sandbox Code Playgroud)

但实际上,你应该使用subprocess

希望这可以帮助