-4

How to display file on the screen in python ?

Note:

I don't want to open for read or write, i want to display the file on the screen, like i double click on the file himself and it's open .

Thank you.

4

2 回答 2

3

在 Windows 中,仅执行文件有效:

import os
os.system('c:/tmp/sample.txt')

基于SOUNIX一个enviroment名为的变量EDITOR,您可以执行以下操作:

import os
import subprocess
try:
    subprocess.call([os.environ['EDITOR'], 'filename'])
except:
    try:
        subprocess.call(['gedit', 'filename'])
    except:
        subprocess.call(['nano', 'filename'])
于 2013-07-20T01:00:50.643 回答
1

你可以试试

import webbrowser
webbrowser.open('yourfile')

或者使用subprocess 模块在您知道路径的任何编辑器中打开您的文件。

于 2013-07-20T00:37:16.123 回答