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


相关文档:

使用eclipse开发Python。

Help-》Software Upates-》Find and Install-》Search for new features to install-》New remote site-》随便起个name如pydev,url填 http://pydev.sf.net/updates/ -》然后照着提示下载安装即可。
Pydev的配置
在Eclipse IDE 下, 打开 Window->Preferences... 对话框,从右侧的树形列表中选择“ PyDev&r ......

呆呆的Python 笔记


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

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

转段Python代码

#==================================================
import wx
import wx.media

class MyFrame(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,-1,title,pos=(150,150),size&;nbsp;=(640, 480),style=wx.MAXIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX| ......

用Python实现网站测试

测试网站:Baidu主页以及相关的页面
主题:黑盒测试,功能测试,性能/压力测试,安全测试, 数据字典管理
1. 测试页面是否可访问的;
1.1 HTTP request status = 200, 页面下载正确
from urllib import urlopen
# set up
url = None
# test
url = urlopen('http://www.baidu.com')
assert url.getcode() == 200
# ......

python访问 sql server

今天试验使用python连接 sql server 服务器。我记得以前使用ado连接access非常顺利,但是今天使用ado连接sql server竟然不成功。在python里面的出错信息都显示为转移序列,费了半天劲才搞明白:无效的类别字符串。
是连接字符串吗?测试了好几个 确认无误的数据库连接字符串,也是如此 。上网搜索,是有可能是 com的类别字 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号