Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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'))
Õâ¸öÍêÃÀÁË¡£


Ïà¹ØÎĵµ£º

python ¼¯ºÏÔËËã

¼¯ºÏÀàÐͲÙ×÷·û£¨ËùÓеļ¯ºÏÀàÐÍ£©
ÁªºÏ( | )
ÁªºÏ(union)²Ù×÷ºÍ¼¯ºÏµÄOR(ÓֳƿɼæÎöÈ¡(inclusive
disjunction))ÆäʵÊǵȼ۵ģ¬Á½¸ö¼¯
ºÏµÄÁªºÏÊÇÒ»¸öм¯ºÏ£¬¸Ã¼¯ºÏÖеÄÿ¸öÔªËØ¶¼ÖÁÉÙÊÇÆäÖÐÒ»¸ö¼¯ºÏµÄ³ÉÔ±£¬¼´£¬ÊôÓÚÁ½¸ö¼¯ºÏÆä
ÖÐ
Ö®Ò»µÄ³ÉÔ±¡£ÁªºÏ·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬union().
Edit By Vheavens
Edit By Vhe ......

PythonÕýÔò±í´ïʽµÄ³£ÓÃÆ¥ÅäÓ÷¨


ÏÂÃæÁгöPythonÕýÔò±í´ïʽµÄ¼¸ÖÖÆ¥ÅäÓ÷¨£º
1.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥Åä×Ö·û´®µÄÈ«²¿»ò²¿·Ö
regex=ur"" #ÕýÔò±í´ïʽ
if re.search(regex, subject):
    do_something()
else:
    do_anotherthing()
2.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥ÅäÕû¸ö×Ö·û´®
regex=ur"\Z" #ÕýÔò±í´ïʽĩβÒÔ\ ......

µÚÒ»¸öpythonС³ÌÐò

ÏеÄÎÞÁľͿ´ÁËÒ»µã¹ØÓÚpythonµÄ»ù´¡ÖªÊ¶£¬µ±Ê±Ò²²»ÖªµÀpythonºÍperlÖ®¼äÕùÂÛµÄÕâôµÄ¼¤ÁÒ£¨Ö÷ÒªÊǵ±Ê±²»ÖªµÀperlÕâ¸öÓïÑÔµÄÐÔÖÊ),ËùÒÔÖ±½Ó¾Í¿´ÁËpython£¬ÏÂÃæÊÇÎҵĵÚÒ»¸öÓÃpythonдµÄС³ÌÐòÔ´Â룬ϣÍûÅóÓÑÃǶà¶àÖ¸½Ì£¬ÓÐʲôÎÊÌâ´ó¼Ò¾¡¹ÜÖ¸Õý£¬ÔÚ´ËÏÈлл´ó¼ÒÁË¡£
[code]
#!/usr/bin/python
import sys, os, re
impor ......

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

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

ºÜÈ«µÄPython×ÊÔ´ÊÕ¼¯

Programming Python, 2nd Edition (O'Reilly)
http://www.osbbs.com/dl/Programming Python, 2nd Edition (O'Reilly).chm
ºÜÈ«ºÜ¾­µäÁËpythonѧϰÈëÃÅ×ÊÁÏ
OReilly - Learning Python:
http://www.osbbs.com/dl/OReilly - Learning Python.chm ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ