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

³õѧÕßÇóÖú£ºÊ¹ÓÃ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


Ïà¹ØÎÊ´ð£º

python½Ì³ÌÖÐʹÓÃÔ´ÎļþµÄÎÊÌâ~~

ʹÓÃÔ´Îļþ

#!/usr/bin/python
# Filename : helloworld.py
print 'Hello World'

ÎÒÔõôҲ¿´²»¶®£¡Ö»ÊÇ×îºóÒ»ÐÐÎÒÖªµÀ~~Ç°ÃæÁ½ÐÐÊÇʲôÒâ˼ÄØ£¿
½Ì³ÌÉÏ˵Èç¹ûÄãʹÓÃIDLE£¬ÇëʹÓò˵ ......

python PILÄ£¿é´ò¿ªÍ¼Æ¬ÎÊÌâ

ÇëÎÊÏ£¬ÎÒµÄÊÇpython2.5°²×°ÁËPILÄ£¿é£¬È»ºó±àд³ÌÐò´ò¿ª±¾»úÉϵÄÒ»¸öͼƬʱ£¬ÎªÊ²Ã´ÀϳöÏÖ´íÎóÄØ£¬ÀÏÊÇÕÒ²»µ½Í¼Æ¬£¬´íÎóÌáʾÈçÏ£ºFile "C:\Python25\Lib\site-packages\PIL\Image.py", line 1888, in o ......

boost.python c++ǶÈëpythonÈçºÎÖØÔØ=£¿

ÎÒÏÖÔÚÓÐÒ»¸öÐèÇóÊÇÕâÑùµÄ
ÎÒÓÐ2¸öÀà
class A
{
public:
int val;
}

class B
{
public:
A a
}

ÏÖÔÚÔڽű¾ÖÐÖ»ÄÜ
b.a.val = 1
ÎÒÔÚpythonÖÐÏëʹÓÃ
b.a = 1
......

Çë½Ì¸ßÊÖ¹ØÓÚpython¿ª·¢webµÄÎÊÌâ¡£

ÇëÎʸßÊÖ£¬ÈçºÎÓÃpython¿ª·¢webʱ£¬²»ÓÃcssÑùʽ±íÖ±½ÓÓÃpythonÓïÑÔʵÏÖÍøÕ¾Ò³ÃæЧ¹ûÔÚ800*600¡¢1200*1600¡¢1024*768µÈÏÔʾ·Ö±æÂʵÄÏÔʾÆ÷ÉÏÕý³£ÏÔʾÄØ£¿£¿
²»Ã÷°×ÄãÒª×öʲô...

1. web¿ª·¢, ʼÖÕ´«Ë͹ýÀ´, ä ......

python 3.xµÄifÓï¾ä

>>> x=-1
>>> if x>0:
print ('11')

>>> else:

SyntaxError: invalid syntax (<pyshell#20>, line 1)
ÍøÉÏËѵÄÒ²ÊÇ£º
>>> x=int(input("Please ent ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ