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

Ç¿´óµÄPythonÉú³ÉÆ÷

Öð²½Ñݽø
f=open('/etc/motd','r')
longest=0
while True:
    lineLen=len(f.readline().strip())
    if not lineLen: break
    if lineLen > longest:
        longest=lineLen
f.close()
return longest
ÎÊÌ⣺һֱռÓÐÎļþ¾ä±úδÊÍ·Å
f=open('/etc/motd','r')
longest=0
allLines=f.readLines()
f.close()
for line in allLines:
    lineLen=len(line.strip())
    if lineLen > longest:
        longest=lineLen
return longest
ÎÊÌ⣺¶ÁÍêÎļþËùÓÐÐÐÔÙ¿ªÊ¼¼ÆË㣬ºÄ·Ñ´óÁ¿ÄÚ´æ
f=open('/etc/motd','r')
allLineLens=[len(x.strip()) for x in f]
f.close()
return max(allLineLens)
ÎÊÌ⣺Îļþµü´úÆ÷Ò»ÐÐÒ»Ðеü´úf£¬Áбí½âÎöÐèÒªÎļþËùÓÐÐж¼»á¶Áµ½ÄÚ´æÖÐ
f=open('/etc/motd','r')
longest=max(len(x.strip()) for x in f)
f.close()
return longest
ÎÊÌ⣺¿ÉÈ¥µôÎļþ´ò¿ªÄ£Ê½£¬ÈÃpythonÈ¥´¦Àí´ò¿ªµÄÎļþ
return max(len(x.strip()) for x in open('etc/motd'))
Õâ¸öÍêÃÀÁË¡£


Ïà¹ØÎĵµ£º

ʹÓÃpdb½øÐÐpythonµÄµ÷ÊÔ

1 ÔÚÏëÒª²åÈë¶ÏµãµÄµØ·½²åÈë´úÂë
                import pdb
                pdb.set_trace()
2È»ºóʹÓÃÖ¸Áî½øÐÐdebug
²é¿´´úÂëÉÏÏÂÎÄ£¬l£¨Ð¡Ð´L£©
¼àÊÓ±äÁ¿ ......

python µÄº¯ÊýDecorators

DecoratorsÊÇpythonÖбȽÏÄÑÒÔÀí½âµÄ¶«Î÷£¬µ±È»Èç¹ûÄã½Ó´¥¹ýjavaµÄannotation£¬»á·¢ÏÖÕâ¸öDecoratorsÔÚÓï·¨ÉϷdz£µÄÏàËÆ£¬µ«ÊÇÁ½ÕßµÄÉè¼Æ¶¯»úȴûʲô¹²Í¬µã£»
ÕâÀï½²µÄpythonÖеÄdecoratorsÊǶÔpythonÖеÄfunction/method×ö×°ÊΣ¬ÕâЩÐÞÊνöÊǵ±ÉùÃ÷Ò»¸öº¯Êý»òÕß·½·¨µÄʱºò£¬²Å»áÓ¦ÓõĶîÍâµ÷Óá£
pythonÖеÄdecorator·Ö ......

Python intÀàÐͲåÈëÊý¾Ý¿â MySQLdb

 def test2():
 32     db = util.DBUnit('mysql_ab')                                    &nb ......

python µÄtimeÄ£°å·­Ò뼰˵Ã÷

python µÄÄÚǶtimeÄ£°å·­Ò뼰˵Ã÷
Ò»¡¢¼ò½é
timeÄ£¿éÌṩ¸÷ÖÖ²Ù×÷ʱ¼äµÄº¯Êý
˵Ã÷£ºÒ»°ãÓÐÁ½ÖÖ±íʾʱ¼äµÄ·½Ê½:
µÚÒ»ÖÖÊÇʱ¼ä´ÁµÄ·½Ê½(Ïà¶ÔÓÚ1970.1.1 00:00:00ÒÔÃë¼ÆËãµÄÆ«ÒÆÁ¿),ʱ¼ä´ÁÊÇΩһµÄ
µÚ¶þÖÖÒÔÊý×éµÄÐÎʽ±íʾ¼´(struct_time),¹²ÓоŸöÔªËØ£¬·Ö±ð±íʾ£¬Í¬Ò»¸öʱ¼ä´ÁµÄstruct_time»áÒòÎªÊ±Çø²»Í¬¶ø²»Í¬
year ......

ÔÚWindowsÏÂʹÓÃPython±à³Ì

Ò»¡¢Ê¹ÓÃPythonÐèÒªÖªµÀµÄ
ÔÚ Windows ÉÏ£¬°²×° Python ÓÐÁ½ÖÖÑ¡Ôñ¡£
1¡¢ActiveState ÖÆ×÷µÄ ActivePython ÊÇרÃÅÕë¶Ô Windows µÄ Python Ì×¼þ£¬Ëü°üº¬ÁËÒ»¸öÍêÕûµÄ Python ·¢²¼¡¢Ò»¸öÊÊÓÃÓÚPython ±à³ÌµÄ IDE ÒÔ¼°Ò»Ð© PythonµÄ Windows À©Õ¹£¬ÌṩÁËÈ«²¿µÄ·ÃÎÊ Windows APIs µÄ·þÎñ£¬ÒÔ¼° Windows×¢²á±íµÄ×¢²áÐÅÏ¢¡£ËäÈ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ