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

Python modules : os, subprocess and commands

1. What’s the difference between all of the os.popen() methods?
popen2 doesn't capture standard error, popen3 does capture standard
error and gives a unique file handle for it. Finally, popen4 captures
standard error but includes it in the same file object as standard
output.
os.popen()   -> stdout
os.popen2() -> (stdin, stdout)
os.popen3() -> (stdin, stdout, stderr)
os.popen4() -> (stdin, stdout_and_stderr)
2. os.popen() vs os.system()
from what I've deciphered, the only differences between os.popen() and os.system() are
a) popen automatically starts a new process while system only does it if you include an &
b) popen hooks onto stdout and stdin.
If so, what's the use of os.system()???
a) is not true. Under Unix both start a new process.
The important difference (as I understand it) is popen lets you interact with the program by reading and writing pipes while it's running. system() is more of a batch mode thing, the program runs to completion, then you get the return status.
>??? If so, what's the use of os.system()?
If you just want to run a shell command and don't need to provide any stdin and don't care about stdout/stderr.
For example, if you just want to copy a directory tree from one place to another:
status = os.system("cp -r srcdir /some/where/else")
If you want to start a program, send it input and/or watch its output as it runs, then use popen().
os.system is a standard call to the C standard function call system().
It doesn't allow you to catch the output of the program like os.popendoes.
os.popen is piped open so that you can capture in your python scripts what the program outputs.
os.system simply calls the outside program and sends it's contents to stdout which can be
redirected to a file in your shell.
Call os.system if your python program doesn't need to capture anything from your outside program.


相关文档:

呆呆的Python 笔记


一些综合的信息
Python
里,缩进很重要。没有尖括号不要紧,

Python
根据缩进来分割语句块。
参数不需要定义,可以直接使用。
Help(var)
查看
var
的帮助。
Var
可以为任何东西,函数,模块,类。
Python
中的字符串是不可变的。
Pass 
表示空语句块。
# 注释
 
String
r‘I&rsquo ......

UltraEdit支持python语言。


为了让UE支持python语言,google了很多,结果都不行,最后看了下面的博客才知道错哪了,总结下以免忘记。
http://wangtao.name/2009/12/20/ultraedit_python.html
在官网上找到python的扩展下载点:http://www.ultraedit.com/downloads/extras.html
有各种语言的扩展,便可以支持语法高亮。
python 2.5:http://www.u ......

python图形处理库PIL(Python Image Library)


原文地址 http://www.javaeye.com/wiki/Python/1371-python-graphics-library-pil-python-image-library-introduction
关于PIL库的一些概念
pil能处理的图片
类型
pil可以处理光栅图片(像素数据组成的的块)。
通道
一个图片可以包含一到多个数据通道,如果这些通道具有相同的维数和深度,Pil允许将这些通道进行叠加 ......

python 中文问题

如果Python源文件中出现中文,需要在源文件第一行加上类似如下的代码页指令:
# -*- coding:gbk -*-
如果程序的运行结果中包含中文,可以在程序开头包含如下代码,就可以正确显示中文结果:
    import sys
    reload(sys)
    sys.setdefaultencoding('gbk')
......

python 正则表达式和re模块

正则表达式是搜索、替换和解析复杂字符模式的一种强大而标准的方法.
正则表达式(或 RE)是一种小型的、高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.字符串也有很多方法,可以进行搜索 (index、find 和 count)、替换 (replace) 和解
析 (split),但它们仅限于处理最简单的情况
re 模块使 P ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号