易截截图软件、单文件、免安装、纯绿色、仅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 module] threading

threading — Higher-level threading interface
This module constructs higher-level threading interfaces on top of the lower level _thread module. See also the queue module.
The dummy_threading module is provided for situations where threading cannot be used because _thread is missing.
  ......

Python and RRD

RRD是Round Robin Database的意思,RRDTool是用来管理RRD的一个工具。RRDTool的主页在这里,Wikipedia的页面在这里。RRD其实就是一个时序数据库,使用一个固定大小的环型buffer,适用于存储一些统计性的信息,如CPU负载呀,气温变化呀。我为什么要说这个东西呢,因为XenServer里的性能统计是用的RRD,你可以访问诸如http:// ......

自动下载并保存博客 Python脚本

谢了一个自动下载指定人的博客的脚本
这个脚本是用来下载csdn博客的
同样的方法可以下载一般其他网站的博客,如sina
有时页面访问会被拒绝,重新运行即可
这种程序是在分析了指定网站,我在这儿是csdn,之后编写出的
会牵涉到网页的编码问题,有时程序运行会因此终止
我自己的博客已经下载忘了
只是下载网页
使用网 ......

Python 有权重的随机选择, Weighted Random Choice

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])
   ......

python应用领域介绍

python应用领域介绍 
Python作为一种功能强大且通用的编程语言而广受好评,它具有非常清晰的语法特点,适用于多种操作系统,目前在国际上非常流行,正在得到越来越多的应用。 
下面就让我们一起来看看它的强大功能: 
Python(派森),它是一个简单的、解释型的、交互式的、可移植的、面向对象的超高级语 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号