Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[python]Öض¨ÏòÊä³ö

  µ÷ÓÃÒ»¸ö¿ØÖÆ̨³ÌÐò£¬»ñÈ¡ËüµÄ±ê×¼Êä³ö£¬»ò°ÑËüµÄ±ê×¼Êä³öÖض¨Ïòµ½½çÃæÉÏ£¬ÕâÀïÖ»½éÉÜÈçºÎ»ñÈ¡ËüµÄ±ê×¼Êä³ö£¬ÒòΪԭÀí¶¼Ò»ÑùµÄ¡£
ʹÓÃpython2.5µÄsubprocessÄ£¿éÀ´ÊµÏÖ¡£
import sys
import subprocess
def RunShellWithReturnCode(command, print_output=False,
universal_newlines=True):
"""Executes a command and returns the output from stdout and the return code.
Args:
command: Command to execute.
print_output: If True, the output is printed to stdout.
If False, both stdout and stderr are ignored.
universal_newlines: Use universal_newlines flag (default: True).
Returns:
Tuple (output, return code)
"""
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=use_shell, universal_newlines=universal_newlines)
if print_output:
output_array = []
while True:
line = p.stdout.readline()
if not line:
break
print line.strip("\n")
output_array.append(line)
output = "".join(output_array)
else:
output = p.stdout.read()
p.wait()
errout = p.stderr.read()
#if print_output and errout:
# print >>sys.stderr, errout
p.stdout.close()
p.stderr.close()
return output, p.returncode
def RunShell(command, silent_ok=False, universal_newlines=True,
print_output=False):
data, retcode = RunShellWithReturnCode(command, print_output,
universal_newlines)
if retcode:
ErrorExit("Got error status from %s:\n%s" % (command, data))
if not silent_ok and not data:
ErrorExit("No output from %s" % command)
return data

   ÉÏÃæµÄ´úÂëÀ´×ÔÓÚ ¿ªÔ´µÄ´úÂëÉó²é¹¤¾ß rietveld µÄ´úÂ룬ÆäÖÐRunShellWithReturnCodeº¯Êý ¾ÍÊÇ·µ»Ø¿ØÖÆ̨µÄ±ê×¼Êä³öºÍ·µ»Ø½á¹û


Ïà¹ØÎĵµ£º

PythonºÍSingleton £¨µ¥¼þ£©Ä£Ê½

ÎÒÖªµÀµÄÒ»ÖÖÔÚ
python
ÖÐ
Singleton mode
µÄʵÏÖÈçÏ£º
class Foo: pass
def
instance():
   
global inst
   
try:
       
inst
   
except:
       
inst =
Foo
()
&n ......

Python±ê×¼¿â randomÄ£¿é


Python±ê×¼¿â-randomÄ£¿é
random Ä£¿é°üº¬Ðí¶àËæ»úÊýÉú³ÉÆ÷. »ù±¾Ëæ»úÊýÉú³ÉÆ÷(»ùÓÚ Wichmann ºÍ Hill , 1982 µÄÊýѧÔËËãÀíÂÛ) ¿ÉÒÔͨ¹ýºÜ¶à·½·¨·ÃÎÊ, Èç Example 2-29 Ëùʾ. 2.17.0.1. Example 2-29. ʹÓà random Ä£¿é»ñµÃËæ»úÊý×Ö File: random-example-1.py import random for i i
¡¡¡¡
random Ä£¿é°üº¬Ðí¶àËæ»úÊýÉ ......

ÓÃPythonʵÏÖ¼òµ¥µÄÒÅ´«Ëã·¨

ÓÃPythonʵÏÖ¼òµ¥µÄÒÅ´«Ëã·¨
2010-02-15 14:00
Õ⼸ÌìÒ»Ö±ÔÚÓÃPythonдһ¸ö¼òµ¥µÄÒÅ´«Ëã·¨£¬ºÃ×Ô¼ºÄÃÀ´ÊµÑé¡£¶Ï¶ÏÐøÐøµÄÕÛÌÚÁ˼¸Ì죬½ñÌìÏÂÎçÖÕÓÚдÁËÒ»¸ö¼òµ¥µÄ³öÀ´¡£Õû¸ö´úÂ뻹ÊÇ·ÂÕÕ¡¶ÓÎÏ·±à³ÌÖеÄÈ˹¤ÖÇÄܼ¼Êõ¡·ÖеĴúÂëÀ´Ð´µÄ¡£Èç¹ûÏë¼òµ¥µÄѧϰһÏÂÒÅ´«Ëã·¨ÒÔ¼°¼òµ¥Ó¦Óá¶ÓÎÏ·±à³ÌÖеÄÈ˹¤ÖÇÄܼ¼Êõ¡·ÊDz»´íµÄÑ¡Ôñ¡£ ......

python°²×°Ö®°²×°Ä£¿éÖÆ×÷

pythonµÄeggÎļþÓеãÏñjavaÖеÄjarÎļþ£¬ÊÇÒ»¸ö¹¤³Ì´ò°üÎļþ£¬±ãÓÚ°²×°²¿Ê𣬽ö´ËÒ»µã£¬¸ø¶àÉÙpythoner´øÀ´Á˶àÉÙ¼¤¶¯¡£
ÈçºÎÖÆ×÷eggÎļþÄØ£¿see¹Ù·½Îĵµhttp://peak.telecommunity.com/DevCenter/PythonEggs£¬
µ½http://pypi.python.org/pypi/setuptoolsÏÂÔØsetuptools°ü£¬È»ºó°²×°£º
python setup.py
1.ÖÆ×÷eggÎļþ
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ