2007年06月27日 星期三 17:00
一个问题哦,有一个问件有若干行,每行由四个项组成,由空格分开。我想把每行按照第一项进行排序,怎么弄啊?每行第一项都是汉字串。 例如: 俊杰 jun4jie2 n 1 俊美 jun4mei3 a 0 俊俏 juan4qiao4 a 2 俊秀 juan4xiu4 a 1 排序……
2007年06月27日 星期三 17:05
ºÃÎÊÌâ¡«£¡ »áµÄ¸ßÊÖ¸ø³ö´úÂë°É¡«¡« ÎÒÒ²ºÜºÃÆæ¶í ÔÚ07-6-27£¬ÕÅÒã <yzhang在nlpr.ia.ac.cn> дµÀ£º > > Ò»¸öÎÊÌâŶ£¬ÓÐÒ»¸öÎʼþÓÐÈô¸ÉÐУ¬Ã¿ÐÐÓÉËĸöÏî×é³É£¬ÓÉ¿Õ¸ñ·Ö¿ª¡£ÎÒÏë°ÑÿÐа´ÕÕµÚÒ»Ïî½øÐÐÅÅÐò£¬ÔõôŪ°¡£¿Ã¿ÐеÚÒ»ÏÊǺº×Ö´®¡£ > ÀýÈ磺 > > ¿¡½Ü jun4jie2 n 1 > ¿¡ÃÀ jun4mei3 a 0 > ¿¡ÇÎ juan4qiao4 a 2 > ¿¡Ðã juan4xiu4 a 1 > > ÅÅÐò¡¡ > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070627/b11ab40a/attachment.htm
2007年06月27日 星期三 17:21
# -*- coding:cp936 -*- f = file('data.txt','rw') data = [(line.split(' ', 2)[0], line) for line in f] f.close() data.sort(cmp = lambda x,y: cmp(x[0],y[0])) print ''.join(map(lambda x:x[1], data)) ÔÚ07-6-27£¬ÕÅÒã <yzhang在nlpr.ia.ac.cn> дµÀ£º > > Ò»¸öÎÊÌâŶ£¬ÓÐÒ»¸öÎʼþÓÐÈô¸ÉÐУ¬Ã¿ÐÐÓÉËĸöÏî×é³É£¬ÓÉ¿Õ¸ñ·Ö¿ª¡£ÎÒÏë°ÑÿÐа´ÕÕµÚÒ»Ïî½øÐÐÅÅÐò£¬ÔõôŪ°¡£¿Ã¿ÐеÚÒ»ÏÊǺº×Ö´®¡£ > ÀýÈ磺 > > ¿¡½Ü jun4jie2 n 1 > ¿¡ÃÀ jun4mei3 a 0 > ¿¡ÇÎ juan4qiao4 a 2 > ¿¡Ðã juan4xiu4 a 1 > > ÅÅÐò¡¡ > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070627/0b1c8ae8/attachment.htm
2007年06月27日 星期三 17:33
ÔËÐÐÒÔºó³öÏÖ´íÎó£º Traceback (most recent call last): File "C:/Python25/text.py", line 2, inf = file('data.txt','rw') IOError: [Errno 2] No such file or directory: 'data.txt' ÔÚ07-6-27£¬lai yonghao <lanphaday在gmail.com> дµÀ£º > > # -*- coding:cp936 -*- > f = file('data.txt','rw') > data = [(line.split(' ', 2)[0], line) for line in f] > f.close() > data.sort(cmp = lambda x,y: cmp(x[0],y[0])) > print ''.join(map(lambda x:x[1], data)) > > > ÔÚ07-6-27£¬ÕÅÒã <yzhang在nlpr.ia.ac.cn> дµÀ£º > > > > Ò»¸öÎÊÌâŶ£¬ÓÐÒ»¸öÎʼþÓÐÈô¸ÉÐУ¬Ã¿ÐÐÓÉËĸöÏî×é³É£¬ÓÉ¿Õ¸ñ·Ö¿ª¡£ÎÒÏë°ÑÿÐа´ÕÕµÚÒ»Ïî½øÐÐÅÅÐò£¬ÔõôŪ°¡£¿Ã¿ÐеÚÒ»ÏÊǺº×Ö´®¡£ > > ÀýÈ磺 > > > > ¿¡½Ü jun4jie2 n 1 > > ¿¡ÃÀ jun4mei3 a 0 > > ¿¡ÇÎ juan4qiao4 a 2 > > ¿¡Ðã juan4xiu4 a 1 > > > > ÅÅÐò¡¡ > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070627/87e79bc4/attachment-0001.html
2007年06月27日 星期三 18:17
文件不存在呀~ On 6/27/07, 王顺翔 <wsxpython at gmail.com> wrote: > > 运行以后出现错误: > > Traceback (most recent call last): > File "C:/Python25/text.py", line 2, in> f = file('data.txt','rw') > IOError: [Errno 2] No such file or directory: ' data.txt' > > 在07-6-27,lai yonghao <lanphaday at gmail.com> 写道: > > > > # -*- coding:cp936 -*- > > f = file('data.txt','rw') > > data = [(line.split(' ', 2)[0], line) for line in f] > > f.close() > > data.sort(cmp = lambda x,y: cmp(x[0],y[0])) > > print ''.join(map(lambda x:x[1], data)) > > > > > > 在07-6-27,张毅 <yzhang at nlpr.ia.ac.cn > 写道: > > > > > > 一个问题哦,有一个问件有若干行,每行由四个项组成,由空格分开。我想把每行按照第一项进行排序,怎么弄啊?每行第一项都是汉字串。 > > > 例如: > > > > > > 俊杰 jun4jie2 n 1 > > > 俊美 jun4mei3 a 0 > > > 俊俏 juan4qiao4 a 2 > > > 俊秀 juan4xiu4 a 1 > > > > > > 排序…… > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese at lists.python.cn > > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Regards. wangyingqi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20070627/453cd320/attachment.html
2007年06月27日 星期三 20:52
建一个 data.txt,把数据放到里面就行了。 (恕我直言)最近发现组里(相对于我的)新手不少,自己信心倍增 顺便提个建议,这样的问题我个人认为还是放到 comp.lang.python 或 cn.bbs.comp.lang.python(如果你英语实在不行)这样热闹的地方去提比较好。
2007年06月28日 星期四 13:12
下面的一段代码是从《简明Python教程》里面摘取出来的一个sample【问题的产生跟摘 取没有关系】。有个奇怪的问题,下面代码部分标记红色的变量使用不同的变量时会报 错! 如使用"karlm"、"f"等变量名时运行正常,但是使用"klarm"、"ff"、"fk"等时运行程 序会报错: Exception exceptions.AttributeError: "'NoneType' object has no attribute 'population'" in<__main__.Person instance at 0xb7c413cc>> ignored 没搞明白什么原因,哪位大虾指点一下!! #!/usr/bin/python class Person: population = 0 def __init__(self, name): self.name = name print '(Initializing %s)' % self.name Person.population += 1 def __del__(self): print '%s says bye.' % self.name Person.population -= 1 if Person.population == 0: print 'I am the last one.' else: print 'There are still %d people left.' % Person.population if __name__ == "__main__": swaroop = Person('Swaroop') karlm = Person('Abdul Kalam') -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20070628/5cba8870/attachment.html
2007年06月28日 星期四 19:21
ÎÒÓÃff£¬fk£¬klarm¶¼ÊÇûÎÊÌâµÄ¡£ On 6/28/07, snoop <hgli0904在gmail.com> wrote: > > > ÏÂÃæµÄÒ»¶Î´úÂëÊÇ´Ó¡¶¼òÃ÷Python½Ì³Ì¡·ÀïÃæժȡ³öÀ´µÄÒ»¸ösample¡¾ÎÊÌâµÄ²úÉú¸úժȡûÓйØϵ¡¿¡£ÓиöÆæ¹ÖµÄÎÊÌ⣬ÏÂÃæ´úÂ벿·Ö±ê¼ÇºìÉ«µÄ±äÁ¿Ê¹Óò»Í¬µÄ±äÁ¿Ê±»á±¨´í£¡ > ÈçʹÓÃ"karlm"¡¢"f"µÈ±äÁ¿ÃûʱÔËÐÐÕý³££¬µ«ÊÇʹÓÃ"klarm"¡¢"ff"¡¢"fk"µÈʱÔËÐгÌÐò»á±¨´í£º > Exception exceptions.AttributeError: "'NoneType' object has no attribute > 'population'" in<__main__.Person instance > at 0xb7c413cc>> ignored > û¸ãÃ÷°×ʲôÔÒò£¬ÄÄλ´óϺָµãһϣ¡£¡ > > #!/usr/bin/python > class Person: > population = 0 > def __init__(self, name): > self.name = name > print '(Initializing %s)' % self.name > Person.population += 1 > > def __del__(self): > print '%s says bye.' % self.name > Person.population -= 1 > if Person.population == 0: > print 'I am the last one.' > else: > print 'There are still %d people left.' % Person.population > > if __name__ == "__main__": > swaroop = Person('Swaroop') > *karlm* = Person('Abdul Kalam') > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Uraka.Lee @ School of Software and Micro-electronic, Peking University, China -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070628/5bbb4410/attachment.html
Zeuux © 2025
京ICP备05028076号