python shell½Å±¾(Ö÷Òª½²¹ÜµÀ²Ù×÷µÄÖ§³Ö)
ÕâÀïÌṩµÄÖ»ÊÇÒ»¸öÖ§³Ö¹ÜµÀµÄÃüÁîÖ´ÐнӿÚ, ÖÁÓÚ»ñÈ¡ÃüÁî, À©Õ¹×Ô¼ºµÄÃüÁî, ¾Í²»ÔÙ׸Êö.
¶ÔÓÚϵͳµÄÃüÁî, ¿ÉÒÔÖ±½Óµ÷ÓÃÕâ¸ö½Ó¿Ú·½·¨, ¶à¸öÃüÁîÖ§³Ö¹ÜµÀ²Ù×÷. ·¢Éú´íÎóʱ, Òý·¢OSError.
1. Åжϴ«ÈëÃüÁîÊÇ·ñÊÇ×Ö·û´®ÀàÐÍ
2. ´«ÈëµÄÿ¸öÃüÁî.
3. ±éÀúËùÓÐÃüÁî.
4. »ñȡÿ¸öÃüÁîµÄÃüÁî¼°²ÎÊý
5. ¶¯Ì¬Ö´ÐÐPopen, ²¢½«·µ»ØÖµ·ÅÈëÁбípopensÖÐ
6. ¶¯Ì¬Ö´Ðй¹½¨µÄPopen, µÚÒ»¸öÖ»ÓÐstdin²»Ê¹ÓùܵÀ, ×îºóÒ»¸östdoutÖ¸¶¨Îªsys.stdout. ÆäÓàµÄ¶¼ÊÇPIPE
7. ±éÀúÈ¡³öPopen¶ÔÏó, ½«Ç°Ò»¸ö¶ÔÏóµÄstdoutдÈëµ½ºóÒ»¸ö¶ÔÏóµÄstdinÖÐ.
'''
Created on 2009-10-21
@author: selfimpr
@blog: http://blog.csdn.net/lgg201
@E-mail: lgg860911@yahoo.com.cn
@function: ²âÊÔ¹ýFreeBSDÏ¿ÉÒÔʹÓÃ. ÊÇÒ»¸öСÁ·Ï°, ×÷ÓÃÊǽ«ÏµÍ³ÃüÁî×÷Ϊ²ÎÊý´«Èë, Ö´ÐÐ. ½ÓÊܵIJÎÊýÖ§³Ö¹ÜµÀ²Ù×÷, ¹ÜµÀ²Ù×÷·ûʹÓÃ|.
'''
from sys import stdout
from subprocess import Popen, PIPE
def pipecmd(cmdstr):
if isinstance(cmdstr, str): # estimate if the argument is string
cmds = cmdstr.split('|') # split intact cmdstr to sigle command
cmds = [cmd.strip() for cmd in cmds] # strip space character
length = len(cmds)
popens = []
for index, cmd in enumerate(cmds): # each all the commands
cmd_args = cmd.split(' ')
cmd_args = [arg.strip() for arg in cmd_args]
try:
#################
# get all the instance of Popen
#################
popens.append(eval('Popen(cmd_args%(stdin)s%(stdout)s)' % \
{'stdin': '' if index == 0 else ', stdin=PIPE', \
'stdout': ', stdout=stdout' if index == length - 1 else ', stdout=PIPE'}))
except OSError, e:
print 'arises os error'
#################
# process pipe
#################
prev = None
for index, popenobj in enumerate(popens):
if not prev:
prev = popenobj
continue
popenobj.stdin.write
Ïà¹ØÎĵµ£º
¡¡¡¡PythonÖпÉÒÔʹÓÃ×°ÊÎÆ÷¶Ôº¯Êý½øÐÐ×°ÊΣ¨»ò˵°ü×°£©£¬ÀûÓÃÕâ¸öÌØÐÔ£¬¿ÉÒԺܷ½±ã¡¢¼ò½àµØ½â¾öһЩÎÊÌ⣬±ÈÈç»ñµÃº¯ÊýÖ´ÐÐʱ¼äµÄÎÊÌâ¡£
¡¡¡¡Ê×ÏÈ£¬ÎÒÃǶ¨ÒåÒ»¸öº¯Êý£¬ÈçÏ£º
¡¡¡¡def exeTime(func):
def newFunc(*args, **args2):
t0 = time.time()
print "@%s, {%s} start" % (time.strftime("%X", time.local ......
PythonµÄÃæÏò¶ÔÏóÐÔÖÊ
ÀàºÍ¶ÔÏóÊÇÃæÏò¶ÔÏó±à³ÌµÄÁ½¸öÖ÷Òª·½Ãæ¡£Àà´´½¨Ò»¸öÐÂÀàÐÍ£¬¶ø¶ÔÏóÕâ¸öÀàµÄ ʵÀý ¡£ÕâÀàËÆÓÚÄãÓÐÒ»¸öintÀàÐ͵ıäÁ¿£¬Õâ´æ´¢ÕûÊýµÄ±äÁ¿ÊÇintÀàµÄʵÀý£¨¶ÔÏ󣩡£
ÐèҪעÒâµÄÊÇ£¬ÔÚPythonÖУ¬¼´±ãÊÇÕûÊýÒ²±»×÷Ϊ¶ÔÏó£¨ÊôÓÚintÀࣩ¡£ÕâºÍC++¡¢Java£¨1.5°æÖ®Ç°£©°ÑÕûÊý´¿´â×÷ΪÀàÐÍÊDz»Í¬µÄ¡£Í¨¹ ......
PythonÖеÄÎļþ²Ù×÷ÒÔ¼°ÊäÈëÊä³ö
ÎÒÃÇ¿ÉÒÔ·Ö±ðʹÓÃraw_inputºÍprintÓï¾äÀ´Íê³ÉÕâЩ¹¦ÄÜ¡£¶ÔÓÚÊä³ö£¬ÄãÒ²¿ÉÒÔʹÓöàÖÖ¶àÑùµÄstr£¨×Ö·û´®£©Àà¡£ÀýÈ磬ÄãÄܹ»Ê¹ÓÃrjust·½·¨À´µÃµ½Ò»¸ö°´Ò»¶¨¿í¶ÈÓÒ¶ÔÆëµÄ×Ö·û´®¡£ÀûÓÃhelp(str)»ñµÃ¸ü¶àÏêÇé¡£
ÁíÒ»¸ö³£ÓõÄÊäÈë/Êä³öÀàÐÍÊÇ´¦ÀíÎļþ¡£´´½¨¡¢¶ÁºÍдÎļþµÄÄÜÁ¦ÊÇ ......
a=1
print id(a)
a=2
print id(a)
a=a+1
print id(a)
-------------------------------------------------------------------------------------------------------------------------
t=6
def tt():
global t
t=t+1
print t
print t
tt()
½ ......
Ŀǰ±àÒëÆ÷£¨Êµ¼ÊÊÇ·ÒëÆ÷£©ÏîÄ¿ÒѾÍê³É£¬¶ÔpythonµÄʹÓÃÓÐÁ˸üÉîµÄ¸ÐÊÜ¡£
³ýÁË֮ǰ˵µÄÒÔÍ⣬ÒÔÏÂÊDz¹³ä¼¸µã£¨ÍêÈ«ÊǸöÈË¿´·¨£©¡£
Ê×ÏÈÊÇpythonÏà¶Ô·¾¶¶ÁÈ¡ÅäÖÃÎļþºÍдÎļþÎÊÌ⣬Ïà¶Ô·¾¶ÔÚpythonÖеÄʹÓøújavaºÍC++²»Í¬¡£ËüÊÇÔÚÄǸöλÖÃÔËÐÐpy½Å±¾£¬¾Í°Ñµ±Ç°Â·¾¶×÷Ϊ¸ù·¾¶¡£È磺µ±ÔÚĿ¼AÏÂÔËÐÐÒ»¸öpy½Å±¾£¬ÄÇôĿ ......