haoshuang3394 发表于 2013-2-5 01:14:26

plural.py源代码分析

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>"""Pluralize English nouns (stage 6)This program is part of "Dive Into Python", a free Python book forexperienced programmers.Visit http://diveintopython.org/ for thelatest version.Command line usage:$ python plural6.py nounnouns"""__author__ = "Mark Pilgrim (mark@diveintopython.org)"__version__ = "$Revision: 1.7 $"__date__ = "$Date: 2004/05/03 19:40:42 $"__copyright__ = "Copyright (c) 2004 Mark Pilgrim"__license__ = "Python"import redef rules(language):    for line in file('plural-rules.%s' % language):      pattern, search, replace = line.split()      #获得分离后的三个字符串      yield lambda word: re.search(pattern, word) and re.sub(search, replace, word)      #每次存储一个变量def plural(noun, language='en'):    """returns the plural form of a noun"""    for applyRule in rules(language):      result = applyRule(noun)      if result: return resultif __name__ == '__main__':    import sys    if sys.argv:      print plural(sys.argv)    else:      print __doc__
页: [1]
查看完整版本: plural.py源代码分析