易截截图软件、单文件、免安装、纯绿色、仅160KB

python 执行系统命令比较

转载自:http://purpen.javaeye.com/blog/98095
python 执行系统命令比较
关键字: python os system 系统命令
在此比较一下两种方法执行系统命令的方法,以方便于日后运用:(
1. os.system()
system(command) -> exit_status  
      
Execute the command (a string) in a subshell.  
  
  
# 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息..  
 
>>> os.system('ls')  #如果再命令行下执行,结果直接打印出来
04101419778.CHM  bash     document   media     py-django  video  
11.wmv           books    downloads  Pictures  python  
all-20061022     Desktop  Examples   project   tools  
  
2.os.popen()
popen(command [, mode='r' [, bufsize]]) -> pipe  
      
Open a pipe to/from a command returning a file object.  
  
# 此种方法不但执行命令还返回执行后的信息对象   
 
>>>tmp = os.popen('ls *.py').readlines()  
  
>>>tmp  
Out[21]:   
['dump_db_pickle.py\n',  
 'dump_db_pickle_recs.py\n',  
 'dump_db_shelve.py\n',  
 'initdata.py\n',  
 '__init__.py\n',  
 'make_db_pickle.py\n',  
 'make_db_pickle_recs.py\n',  
 'make_db_shelve.py\n',  
 'peopleinteract_query.py\n',  
 'reader.py\n',  
 'testargv.py\n',&n


相关文档:

用 python 快速搭建网游服务器

赖勇浩(http://laiyonghao.com)
今天(2009年5月31日) OurPNP.org 搞了个聚会活动,弄了十几二十个人在广州海珠广场的堂会呆了五个小时,创下了我在 K 房呆的最长时间纪录。应他们的邀请,我做了个题为《用 python 快速搭建网游服务器》的小演讲,因为那边的电视竟然不能接电脑,所以讲的时候没有能够参照 PPT 来讲,观 ......

Python: python写的一个简单网络词典

闲来无事, 玩玩python...
是采用有道翻译, 然后抓取网页的.
import re, urllib
url="http://dict.youdao.com/search?le=eng&q="
print ("input q to exit")
while 1:
word = raw_input(">>>")
if word=="q":
exit()
else:
word = word.replace(' ', '+')
url += word
u ......

Python: python的简单表达式计算器

这是一个简单的表达式计算器, 不太懂用Tkinter写GUI, 参考了别人的代码
from __future__ import division
from Tkinter import Tk, Entry, Button, Label, mainloop
from tkFont import Font
def get_value ():
v = ''
try:
v = eval(text.get()) #use eval to calculate the vlaue of the text
except:
pa ......

python decorator

1.常用方法,不带参数
def decator(func):
    def inner_func(*args):
        args = (i * 2 for i in args)
        return func(*args)
    return inner_func
   
@decator
def add(a, ......

python decorator

1.常用方法,不带参数
def decator(func):
    def inner_func(*args):
        args = (i * 2 for i in args)
        return func(*args)
    return inner_func
   
@decator
def add(a, ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号