Ç¿´óµÄ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'))
Õâ¸öÍêÃÀÁË¡£
Ïà¹ØÎĵµ£º
¼¯ºÏÀàÐͲÙ×÷·û£¨ËùÓеļ¯ºÏÀàÐÍ£©
ÁªºÏ( | )
ÁªºÏ(union)²Ù×÷ºÍ¼¯ºÏµÄOR(ÓֳƿɼæÎöÈ¡(inclusive
disjunction))ÆäʵÊǵȼ۵ģ¬Á½¸ö¼¯
ºÏµÄÁªºÏÊÇÒ»¸öм¯ºÏ£¬¸Ã¼¯ºÏÖеÄÿ¸öÔªËØ¶¼ÖÁÉÙÊÇÆäÖÐÒ»¸ö¼¯ºÏµÄ³ÉÔ±£¬¼´£¬ÊôÓÚÁ½¸ö¼¯ºÏÆä
ÖÐ
Ö®Ò»µÄ³ÉÔ±¡£ÁªºÏ·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬union().
Edit By Vheavens
Edit By Vhe ......
ÏÂÃæÁгöPythonÕýÔò±í´ïʽµÄ¼¸ÖÖÆ¥ÅäÓ÷¨£º
1.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥Åä×Ö·û´®µÄÈ«²¿»ò²¿·Ö
regex=ur"" #ÕýÔò±í´ïʽ
if re.search(regex, subject):
do_something()
else:
do_anotherthing()
2.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥ÅäÕû¸ö×Ö·û´®
regex=ur"\Z" #ÕýÔò±í´ïʽĩβÒÔ\ ......
ÏеÄÎÞÁľͿ´ÁËÒ»µã¹ØÓÚpythonµÄ»ù´¡ÖªÊ¶£¬µ±Ê±Ò²²»ÖªµÀpythonºÍperlÖ®¼äÕùÂÛµÄÕâôµÄ¼¤ÁÒ£¨Ö÷ÒªÊǵ±Ê±²»ÖªµÀperlÕâ¸öÓïÑÔµÄÐÔÖÊ),ËùÒÔÖ±½Ó¾Í¿´ÁËpython£¬ÏÂÃæÊÇÎҵĵÚÒ»¸öÓÃpythonдµÄС³ÌÐòÔ´Â룬ϣÍûÅóÓÑÃǶà¶àÖ¸½Ì£¬ÓÐʲôÎÊÌâ´ó¼Ò¾¡¹ÜÖ¸Õý£¬ÔÚ´ËÏÈлл´ó¼ÒÁË¡£
[code]
#!/usr/bin/python
import sys, os, re
impor ......
Ò»¡¢Ê¹ÓÃPythonÐèÒªÖªµÀµÄ
ÔÚ Windows ÉÏ£¬°²×° Python ÓÐÁ½ÖÖÑ¡Ôñ¡£
1¡¢ActiveState ÖÆ×÷µÄ ActivePython ÊÇרÃÅÕë¶Ô Windows µÄ Python Ì×¼þ£¬Ëü°üº¬ÁËÒ»¸öÍêÕûµÄ Python ·¢²¼¡¢Ò»¸öÊÊÓÃÓÚPython ±à³ÌµÄ IDE ÒÔ¼°Ò»Ð© PythonµÄ Windows À©Õ¹£¬ÌṩÁËÈ«²¿µÄ·ÃÎÊ Windows APIs µÄ·þÎñ£¬ÒÔ¼° Windows×¢²á±íµÄ×¢²áÐÅÏ¢¡£ËäÈ ......
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
......