Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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º¯Êý ¾ÍÊÇ·µ»Ø¿ØÖÆ̨µÄ±ê×¼Êä³öºÍ·µ»Ø½á¹û


Ïà¹ØÎĵµ£º

Amusing Python 2: range/xrange

ÕâÁ½¸ö»ù±¾É϶¼ÊÇÔÚÑ­»·µÄʱºòÓá£
Python
´úÂë < type="application/x-shockwave-flash" width="14" height="15" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=for%20i% ......

python formatterÄ£¿é

formatter Ä£¿é
formatter Ä£¿éÌṩÁËһЩ¿ÉÓÃÓÚ htmllib µÄ¸ñʽÀà( formatter classes ).
ÕâЩÀàÓÐÁ½ÖÖ, formatter ºÍ writer . formatter ½« HTML ½âÎöÆ÷µÄ±êÇ©ºÍÊý¾ÝÁ÷ת»»ÎªÊʺÏÊä³öÉ豸µÄʼþÁ÷( event stream ), ¶ø writer ½«Ê¼þÁ÷Êä³öµ½É豸ÉÏ.
´ó¶àÇé¿öÏÂ, Äã¿ÉÒÔʹÓà AbstractFormatter Àà½øÐиñʽ»¯. Ëü»á¸ù¾ ......

python Êý×飬ÐòÁУ¬×ֵ䣬ÁÐ±í£¬Ðò±í£¬Ôª×棨tuple£©

python ûÓÐÊý×éµÄÊý¾Ý½á¹¹
#list ÐòÁÐ
sample_list = [1,2,3,'abc']
#dictionary ×Öµä
sample_dic = {"key":value, 2:3}
#tuple Ö»¶ÁµÄÐòÁÐ
sample_tuple = (1,3,"ab")
Ðò±í
    Ðò±íÓÉһϵÁÐÖµÓöººÅ·Ö¸ô¶ø³É
    Ðò±íÓë×Ö·û´®Ò»ÑùÊDz»¿É±äµÄ£º²»ÔÊÐí¶ÔÐ ......

PythonµÄlambdaº¯ÊýÓëÅÅÐò

Ç°¼¸Ìì¿´µ½ÁËÒ»ÐÐÇó1000µÄ½×³ËµÄPython´úÂ룺
print
  
reduce
(
lambda
  
x
,
y
:
x
*
y
,
  
range
(
1
,
  
1001
))

Ò»ÏÂ×Ó±»python´úÂëµÄ¾«¼ò
Óë½ô´ÕËùÕÛ·þ£¬¹Ê¶Ô´úÂë½øÐÐÁ˼òµ¥µÄ·ÖÎö¡£
reduceÓërange¶¼ÊÇPythonµÄÄÚÖú¯Êý¡£
range£¨1£¬10 ......

python ³õÌåÑé

windowsÏÂ
1 ÏÂÔØpython°²×°°ü£¬ һ·ÏÂÈ¥°²×°
2 ÏÂÔØmysqldb°²×°
3 ÏÂÔØdjangoÎļþ£¬ dyango-admin.py install Íê³É
£­£­£­£­£­Èç¹ûÆô¶¯ºó±¨´íimport error: dll load failed. ÐèÒªÔÚsite-packageÏÂÔö¼Ódll: libguide40.dll  libmmd.dll  libmySQL.dll
´´½¨Ó¦ÓÃºó£¬ manage.py µÄprogram argumentÖÐÓ¦ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ