python核心編程十四章練習

14-3

fn = raw_input('$py:')
execfile(fn)

14-4

import os
from subprocess import call


os.system('dir')
call('dir', shell=True)

14-5

from commands import getoutput  
      
output = getoutput('ls')  

14-6

from subprocess import Popen, PIPE

fn = Popen('dir', stdout=PIPE, shell=True)

for eachline in fn.stdout:
    print eachline

14-8

import sys


def foo():
    print 'exit .. . '

sys.exitfunc = foo
print '123'

14-9

import os


while True:
    cmd = raw_input("$:")
    if cmd == 'exit':
        break

    f = os.popen(cmd)
    for line in f:
        print line,


發佈了30 篇原創文章 · 獲贊 7 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章