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

ÇóÖúpythonµÄ×Ö·û´®´¦Àí

ÐèÇó£º
Îļþa.txtÄÚÈÝÈçÏÂ
>> cat a.txt
/* ME Type=DEC, Version=V100R003C01*/
/* ME Type=NOV, Version=V100R003C00*/
/* ME Type=CCVS, Version=V100R003C03*/
/* ME Type=OCTOB, Version=V100R003C08*/

ÇëÎÊÈçºÎʹÓÃpython½Å±¾»ñÈ¡ÎļþÖеÄME type£¬Ê¹Ö®¶ÔÊý×éa¸³Öµ£º
a1=DEC
a2=NOV
a3=CCVS
a4=OCTOB
re.match

´óÏÀ£¬Çë°ïæдһ¸ö¼òµ¥Àý×Ó£¬¸Õ¿ªÊ¼Ñ§python£¬Ð»Ð»£¡


¸ß¼¶µãÕâÑù£º
Python code:
import re

reg = re.compile(r'Type=(\w*),')

def GetType(str):
match = reg.search(str)
if match is not None:
return match.groups(0)[0]

f = open('a.txt')
a = map(GetType, f)
print a
f.close()


µ±È»Èç¹ûÄãµÄÊý¾ÝÏ൱¹æ·¶£¬Ò»¶¨ÊÇÒÔType=Ϊǰµ¼£¬Ò²¿ÉÒÔ²»ÓÃÕýÔò£º
Python code:
import re

prefix = 'Type='
def GetType(str):
for i in str.split():
if i.startswith(prefix):
return i[len(prefix):-1]

f = open('a.txt')
a = map(GetType, f)
print a
f.close()
ÕâÖ»ÊǾٸöÀý×Ó£¬Äã¶ÔÊý¾ÝÔ½Á˽⣬´¦ÀíÊֶξÍÔ½¶à¡£

re.findall('''Type=(.*?),''', str)

import re

f = open('t.txt')                 


Ïà¹ØÎÊ´ð£º

[ÌáÎÊ]Python ÈçºÎºöÂÔ whitespace ¶ÁÈë

Ïñ C µÄ scanf() ÄÇÑù
±ÈÈç¶ÁÈë 1 2 3 a b c
ÿ´Î¶ÁÈëÒ»¸ö
ÏÂÃæÕâ¸öÓ¦¸ÃÊÇÄãÏëÒªµÄ°É£º
Python code:

>>> k = raw_input()
0 0123 ds dsl sd
>>> k
'0 0123 ds dsl sd'
>>> ......

Ë­ÍÆ¼öÒ»±¾Ñ§Ï°PYTHONµÄÊ飬лл

Ë­ÍÆ¼öÒ»±¾Ñ§Ï°PYTHONµÄÊ飬лл
¡¶python¼òÃ÷½Ì³Ì¡·£¬¡¶pythonºËÐıà³Ì¡·

×÷Ϊϵͳ¹ÜÀí·½Ãæ£¬¡¶Python UNIXºÍLinuxϵͳ¹ÜÀíÖ¸ÄÏ¡·ÊDZ¾·Ç³£²»´íµÄÊé¡£
http://club.book.csdn.net/pic3/255142.jpg

ÒýÓÃ
×÷Î ......

pythonÔõôprint 'hello world'

´ó¼ÒºÃ£¬ÎÒÊÇÒ»¸öÐÂÊÖ£¬¸Õ¿ªÊ¼Ñ§python£¬µ«ÊǸտªÊ¼µÄhelloworld¶¼Ã»·¨´òÓ¡£¬ÈÃÎÒºÜÎÞÄΡ£
ÎÒµÄpython°²×°Â·¾¶Îªf:\python31¡£ÔÚpathÖÐÒ²ÉèÖöÔÁË£¬ÔÚwindowsÏÂÔËÐÐÊÇÕâÑùÏÔʾµÄ£¬Ï£Íû¸÷λǰ±²Ö¸µãһϡ£Ð»Ð»
Pyth ......

python¸ù¾Ýfeedparser¶ÁÈ¡xmlµÄʱ¼ä

feedparserµ¼ÈëÕâ¸ö°ü ¶ÁxmlµÄtitle£¬link ¶¼Ã»ÎÊÌâ ¾ÍÊÇʱ¼ä¶ÁÈ¡²»³öÀ´
´íÎó£º
print d['feed']['%s lastBuildDate']

return UserDict.__getitem__(self, realkey)
KeyError: ' ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ