开发者

Opening file from python

开发者 https://www.devze.com 2023-03-06 03:32 出处:网络
In my python file, I create an *.bmp image, which I the open to check 开发者_开发知识库everything went fine.

In my python file, I create an *.bmp image, which I the open to check 开发者_开发知识库everything went fine.

It is a bit of a hassle to open this each time I run my program (I know, I'm too lazy) and using show seems counterintuitive, since it freezes the execution and I can't keep it open.

Which is the command in python to open files?, you know like a:

command='gedit file.txt'
pythonmagic.execute(command)

Obviously pythonmagic and the syntax are the things I'm missing.

Thanks a lot


Perhaps you want the subprocess module.

import subprocess
proc = subprocess.Popen(['gedit', 'file.txt'])

The above code will open gedit with the single argument 'file.txt' (i.e. open the file in gedit).

If you add the line,

proc.wait()

then the script will wait until you close gedit, should you ever want that.

0

精彩评论

暂无评论...
验证码 换一张
取 消