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

ÓÃpythonµÄcmdÄ£¿éдһ¸ö¼òµ¥µÄshell

 from cmd import *
class MyShell(Cmd):
    def preloop(self):
        print "print this line before entering the loop"
            
    def postloop(self):
        print "print this line after leaving the loop"
    
    def precmd(self, line):
        print "print this line before do a command"
        return Cmd.precmd(self, line)
    
    def postcmd(self, stop, line):
        print "print this line after do a command"
        return Cmd.postcmd(self, stop, line)   
            
    def do_test(self, line):
        ''' test command, just print the arguments except some special ones'''
        if line == "exit":
            exit()
        else:
            print line
    
MyShell().cmdloop()
#¼Ì³ÐcmdÄ£¿éµÄCmdÀàʵÏÖ
#shellÖеÄÃüÁîxxÔÚÀàÖжÔÓ¦µÄº¯ÊýÃûΪdo_xx
#lineÊÇshellÖÐÊäÈëµÄÃüÁîÐвÎÊý


Ïà¹ØÎĵµ£º

ת£ºPythonµÄsort()

֮ǰѧϰµÚ¾ÅÕµÄÅÅÐòС½áµÄʱºò£¬¶Ôsort()ÅÅÐò·½·¨²»Àí½â£¬ÒòΪÀ¨ºÅÀïÃæ´øÁË×Ô¶¨ÒåµÄ±È½Ïº¯Êý¡£
ºóÀ´²éÊֲᣬ²Å·¢ÏÖsort()ÀïÃæ±¾À´¾Í´øÁËÕâÑùµÄ²ÎÊý¡£Äܹ»×Ô¶¨Òå±È½Ï·½·¨£¬È·ÊµºÜÁé»î¡£
²»½öÈç´Ë£¬ÔÚÍøÉϲ鵽һ¸ö²©¿Í£¬×÷Õß²»µ¥Í£ÁôÔÚÕâ±íÃæ£¬»¹²é¾¿ÁËsort()µÄÅÅÐòËã·¨£¬È·ÊµÓÐÒâ˼¡£
È«Îij­Â¼ÈçÏ£º
http://blog.done ......

[Python ѧϰ]2.5°æyield֮ѧϰÐĵÃ

(ת)[Python ѧϰ]2.5°æyield֮ѧϰÐĵÃ
 
ÔÚ shhgs ·¢²¼Á˹ØÓÚ¡¶ Py 2.5 what's new Ö® yield¡·Ö®ºó£¬Ô­À´ÎÒ²»ÊÇÌØ±ð¹Ø×¢ yield µÄÓ÷¨£¬ÒòΪ¶ÔÓÚ2.3ÖмÓÈëµÄyieldÏà¶ÔÀ´Ëµ¹¦Äܼòµ¥£¬ËüÊÇ×÷Ϊһ¸ö generator ²»¿ÉȱÉÙµÄÒ»ÌõÓï¾ä£¬Ö»Òª°üº¬ËüµÄº¯Êý¼´ÊÇÒ»¸ö generator ¡£µ«ÔÚ2.3ÖУ¬generator ²»ÄÜÖØÈ룬²»ÄÜÔÚÔËÐй ......

pythonѧϰ

3. Dictionaries ×ÖµäÀàÐÍ
     PythonÖУ¬×ÖµäÀàÐͲ¢²»ÊÇ˳ÐòÈÝÆ÷£¬¶øÀàËÆc++ÖеĹØÁªÈÝÆ÷(map)£¬DictionariesÖд洢µÄÊǼü/Öµ ¶Ô£¬ºÍmap²»Í¬µÄÊÇ£¬PythonµÄDictionariesÖпÉÒÔ´æÈÎÒâ¶ÔÏóÀàÐÍ¡£DictionariesÀàÐÍÒ²ÊǿɱäµÄ£¬ºÍListsÒ»Ñù£¬¿ÉÒÔÔ­µØÐ޸ģ¨Í¨¹ýϱêÐ޸ģ©¡£
    ÏÂÃæÍ¨ ......

Python¶ÁдÎļþ


PythonÖÐÎļþ²Ù×÷¿ÉÒÔͨ¹ýopenº¯Êý£¬ÕâµÄÈ·ºÜÏñCÓïÑÔÖеÄfopen¡£Í¨¹ýopenº¯Êý»ñȡһ¸öfile object£¬È»ºóµ÷ÓÃread()£¬write()µÈ·½·¨¶ÔÎļþ½øÐжÁд²Ù×÷¡£
1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt' ......

python pyc

 Ê²Ã´ÊÇpycÎļþ
pycÊÇÒ»ÖÖ¶þ½øÖÆÎļþ£¬ÊÇÓÉpyÎļþ¾­¹ý±àÒëºó£¬Éú³ÉµÄÎļþ£¬ÊÇÒ»ÖÖbyte code£¬pyÎļþ±ä³ÉpycÎļþºó£¬¼ÓÔØµÄËÙ¶ÈÓÐËùÌá¸ß£¬¶øÇÒpycÊÇÒ»ÖÖ¿çÆ½Ì¨µÄ×Ö½ÚÂ룬ÊÇÓÉpythonµÄÐéÄâ»úÀ´Ö´Ðеģ¬Õâ¸öÊÇÀàËÆÓÚJAVA»òÕß.NETµÄÐéÄâ»úµÄ¸ÅÄî¡£pycµÄÄÚÈÝ£¬ÊǸúpythonµÄ°æ±¾Ïà¹ØµÄ£¬²»Í¬°æ±¾±àÒëºóµÄpycÎļþÊDz»Í¬µÄ£¬2 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ