³õѧÕßÇóÖú£ºÊ¹ÓÃpython½øÐÐÎı¾ËÑË÷
ÏÖÔÚÓÐÒ»¸öÎı¾£¬ÄÚÈÝÈçÏ£º
>>cat a.txt
a=1,befc
a=11,azxv
a=2,azvf
a=231,fffe
a=24,zefg
ÐèÇó£º
дһÍêÕûpython³ÌÐò¶ÔÆä×Ö·û´®½øÐÐÅÅÐò´¦Àí£¬ÅÅÐò½á¹ûÈçÏ£º
a=1,befc
a=2,azvf
a=11,azxv
a=24,zefg
a=231,fffe
ÏÈ×Ô¼º¶¥Ò»¸ö^_^
ÕâÑù¾Í¿ÉÒÔÁË
Python code:
import re
file_a = open('a.txt')
pattern = re.compile('a=(\d+),(\w+)')
dict_1 = {}
for line in file_a:
s = pattern.match(line).group(1)
dict_1[int(s)] = line
list_1 = dict_1.keys()
list_1.sort()
for i in list_1:
print dict_1[i]
def my_cmp(a, b ):
a_value = int(a.lstrip('a=').split(',')[0])
b_value = int(b.lstrip('a=').split(',')[0])
return cmp(a_value, b_value)
lines = [ l.strip() for l in open('t.txt') if l.strip() ]
for l in sorted(lines, cmp = my_cmp):
print l
´óÐÍÎļþ¿ÉÄÜ»á¹Òµô
´óÐÍÎļþ
http://code.activestate.com/recipes/576755/
¶àл¸÷λ´óÏÀ£¬°´¶þÂ¥¡¢ÈýÂ¥µÄcodeÒѾÑéÖ¤okay£¬ÔÙÇë½ÌÏ£º
Èç¹ûÎı¾±ä³É¶à¶Î£¬Ã¿¶Îͨ¹ý/*CSDN*/·Ö¿ª,ÖмäÓпÕÐС£¶ÎµÄÊýÁ¿Êµ¼ÊÇé¿öºÜ¶à£¬²¢ÇÒÿ¶ÎÊý×ÖǰµÄË÷ÒýÏàͬ£¬µ«²»Í¬¶Î¼äµÄË÷Òý²»Í¬£©
>>cat a.t
Ïà¹ØÎÊ´ð£º
s='aaa111aaa,bbb222,333ccc,444ddd444,555eee666,fff777ggg'
ÓÃÕýÔò±í´ïʽȡ³ö ǰºó×ÖĸÏàͬµÄÊý¾Ý ½á¹ûÈçÏÂ:
111 ddd
лл~
Python code:
import re
s='aaa111aaa,bbb222,333ccc,444ddd444,555eee666,ff ......
·¢ÏÖpython2.6
import httplib
conn=httplib.HTTPSConnection('x.x.x.x')
conn.request('','')
rd=conn.getresponse()
conn.close()
ÕâÑù½áÊøºó»á±ä³ÉCLOSE_WAIT״̬£¬ÎÒ ......
ÇëÎʸßÊÖ£¬ÈçºÎÓÃpython¿ª·¢webʱ£¬²»ÓÃcssÑùʽ±íÖ±½ÓÓÃpythonÓïÑÔʵÏÖÍøÕ¾Ò³ÃæÐ§¹ûÔÚ800*600¡¢1200*1600¡¢1024*768µÈÏÔʾ·Ö±æÂʵÄÏÔʾÆ÷ÉÏÕý³£ÏÔÊ¾ÄØ£¿£¿
²»Ã÷°×ÄãÒª×öʲô...
1. web¿ª·¢, ʼÖÕ´«Ë͹ýÀ´, ä ......
ÈçºÎʹÓÃpython,½«ÏÂÃæµÄÍøÒ³
http://quotes.money.163.com/corp/1034/code=600221.html
ÄÇÕÅ×ʲú¸ºÕ®±íץȡ³öÀ´£¬·¢µ½Ò»¸öÎı¾ÎļþÖУ¿
ÇëÁôÏÂqq,ÎÒ°ÝÄãΪʦ
Python code:
import re
import url ......
ÎÒÏëÓÃpython½âÎöÍøÒ³ÖеÄurl ÔÚÏÂÔØÖ®Ç°, ÎÒÏëÏÈ·¢Ò»¸öheadÇëÇó ²»ÐèÒªÏÂÔØÕû¸öÍøÒ³, ÏÈ»ñµÃ¸ÃÍøÕ¾µÄheadÐÅÏ¢, ¶ÁȡһЩÐÅÏ¢Ö®ºó ÔÚµ÷ÓÃÕâЩ¿âµÄread·½·¨À´¶ÁÈ¡Õû¸öÍøÒ³ ¸ÃÔõô²Ù×÷ÄØ ¶àл
°ï¶¥ÁË
ÓÐÈËÄÜÖ¸½ÌÒ» ......