ÇóÖú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')
Ïà¹ØÎÊ´ð£º
ʹÓÃÔ´Îļþ
#!/usr/bin/python
# Filename : helloworld.py
print 'Hello World'
ÎÒÔõôҲ¿´²»¶®£¡Ö»ÊÇ×îºóÒ»ÐÐÎÒÖªµÀ~~Ç°ÃæÁ½ÐÐÊÇʲôÒâË¼ÄØ£¿
½Ì³ÌÉÏ˵Èç¹ûÄãʹÓÃIDLE£¬ÇëʹÓò˵ ......
·¢ÏÖpython2.6
import httplib
conn=httplib.HTTPSConnection('x.x.x.x')
conn.request('','')
rd=conn.getresponse()
conn.close()
ÕâÑù½áÊøºó»á±ä³ÉCLOSE_WAIT״̬£¬ÎÒ ......
Ïëͨ¹ýpython postÀ´ÊµÏÖ×Ô¶¯µÇ¼ÐÂÀËΧ²±ÒÑ»ñµÃµÇ¼ºóÒ³ÃæµÄÔ´Âë
µ«ÊÇ×ÐϸµÄ¿´ÁËϵÇÂ¼Ò³ÃæµÄÔ´Âë
HTML code:
<body style=" background:#C4EFF4 url(http://simg.sinajs.cn/miniblog/images/commo ......
±ÈÈçÎÒÐèÒªÓÃpython ¶Ôwin32³ÌÐò½øÐÐÒ»¶¨µÄ¿ØÖÆ
¶ÔtextboxÊäÈëÒ»´®×Ö·û´®
°´Ä³¸öbotton
¶ÔlistboxÀïµÄµÄÄÚÈݶÁÈ¡£¬´æ³É×Ö·û´®
¸ÃÈçºÎ²Ù×÷£¿
»òÕßÄÄÀïÓÐÎĵµÀý×Ó£¿
·Ç³£¸Ðл
......