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...
是采用有道翻译, 然后抓取网页的.
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 ......
multiprocessing — Process-based “threading” interface
Introduction
multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Glo ......
写了几个有关operaminimod的python小程序
firefox->opm书签转换
import re
def pipeiwangzhi(a):
s=[]
pp= re.compile(r'<DT><A HREF="(.*)" ADD_DATE=(.*>)(.*)</A>')
m=pp.search(a)
s1=[]
  ......
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, ......
1 遍历文件夹和文件
import os
import os.path
# os,os.path里包含大多数文件访问的函数,所以要先引入它们.
# 请按照你的实际情况修改这个路径
rootdir = " d:/download "
for parent, dirnames, filenames in os.walk(rootdir):
  ......