Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ÖÐÒ»Öֻص÷·½Ê½µÄʵÏÖ

#¹ØÓڻص÷¹¦ÄܵIJâÊÔ
#FunctorÊÇÕâÖֻص÷¹¦ÄܵĹؼü¶ÔÏó
class Functor:
    """Simple functor class."""
    def __init__( self, fn, *args ):
        self.fn = fn
        ......

ʹÓà Django ºÍ Python ¿ª·¢ Web Õ¾µã


 
 
Ian Maurer (ian@itmaurer.com), ×ÊÉî¹ËÎÊ, Brulant, Inc.
2006 Äê 7 ÔÂ 03 ÈÕ
±¾ÏµÁÐÎÄÕÂÒ»¹²ÓÐÁ½Æª£¬±¾ÎÄÊÇÆäÖеĵÚһƪ¡£ÔÚÕâһƪÎÄÕÂÖУ¬ÎÒÃǽ«Õ¹Ê¾ Django µÄÓ÷¨£¬Django ÊÇ Python ±à³ÌÓïÑÔÇý¶¯µÄÒ»¸ö¿ªÔ´Ä£ÐÍ-ÊÓͼ-¿ØÖÆÆ÷£¨MVC£©·ç¸ñµÄ Web Ó¦ÓóÌÐò¿ò¼Ü¡£Ê¹Óà Django£¬ÎÒÃÇÔÚ¼¸·ÖÖÓÖ®ÄÚ¾ ......

ÉæË®The Python Challenge

ÔÚStack Overflow ÉÏ¿´µ½Ñ§Ï°Python µÄÒ»¸ö·½·¨ÊÇÓÃPython ÆƽâThe Python Challenge¡£µ«ÎÒϲ»¶ÓÃRuby£¬Ë­¹ÜµÃ×ÅÄØ^_^
0. ÈëÃŹغܼòµ¥¡£
p 2**38 
1. ÆƽâÒ»¶Î»°£¬¹Û²ìͼƬºÜÈÝÒ×·¢ÏÖ½âÂë±í°Ñ×Öĸ±íÑ­»·ÓÒÒÆÁ½Î»¡£
riddle = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl ......

pythonͼÐδ¦Àí¿âPIL(Python Image Library)


Ô­ÎĵØÖ· http://www.javaeye.com/wiki/Python/1371-python-graphics-library-pil-python-image-library-introduction
¹ØÓÚPIL¿âµÄһЩ¸ÅÄî
pilÄÜ´¦ÀíµÄͼƬ
ÀàÐÍ
pil¿ÉÒÔ´¦Àí¹âդͼƬ(ÏñËØÊý¾Ý×é³ÉµÄµÄ¿é)¡£
ͨµÀ
Ò»¸öͼƬ¿ÉÒÔ°üº¬Ò»µ½¶à¸öÊý¾ÝͨµÀ£¬Èç¹ûÕâЩͨµÀ¾ßÓÐÏàͬµÄάÊýºÍÉî¶È£¬PilÔÊÐí½«ÕâЩͨµÀ½øÐеþ¼Ó ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ