문제

I have a notepad file in my PC with path D:/example.txt,how can i display this file using my python code.

도움이 되었습니까?

해결책

If you mean open the file with notepad:

Using os.startfile (only available in Windows):

import os
os.startfile(r'd:\example.txt')

Using subprocess.Popen or subprocess.call:

import subprocess
subprocess(['notepad', r'd:\example.txt'])

To print to console

import sys

with open(r'D:\example.txt') as f:
    sys.stdout.writelines(f)

with open(r'D:\example.txt') as f:
    for line in f:
        print line.rstrip('\n')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top