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
相关文档:
赖勇浩(http://laiyonghao.com)
今天(2009年5月31日) OurPNP.org 搞了个聚会活动,弄了十几二十个人在广州海珠广场的堂会呆了五个小时,创下了我在 K 房呆的最长时间纪录。应他们的邀请,我做了个题为《用 python 快速搭建网游服务器》的小演讲,因为那边的电视竟然不能接电脑,所以讲的时候没有能够参照 PPT 来讲,观 ......
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, ......
import random def windex(lst):
'''an attempt to make a random.choose() function that makes weighted choices
accepts a list of tuples with the item and probability as a pair'''
wtotal = sum([x[1] for x in lst])
......
'''gen_python_api.py generates a python.api file for SciTE
The generated api file includes
*) all Python keywords
*) all builtin functions
*) all module attributes
Module functions are represented by their docstring if available,
otherwise by the function definition from the source file. ......
Python已经是3.1版本了,与时俱进更新教程.
本文适合有Java编程经验的程序员快速熟悉Python
本文程序在windows xp+python3.1a1 测试通过.
本文提到的idle指python shell,即安装python后你在菜单看到的IDLE(python gui)
在idle里ctrl+n可以打开一个新窗口,输入源码后ctrl+s可以保存,f5运行程序.
凡打开新窗口即指ctrl ......