Python论坛  - 讨论区

标题:[python-chinese] python 2.3和2.4

2007年01月09日 星期二 17:05

适兕 lijiangsheng1在gmail.com
星期二 一月 9 17:05:10 HKT 2007

ÈçÏ´úÂë
import shelve
fieldnames = ('name', 'age', 'job', 'pay')
maxfield   =max(len(field) for field in fieldnames)
db = shelve.open('class-shelve')

while True:
    key = raw_input('\nKey? => ')       # key or empty line, exc at eof
    if not key: break
    try:
        record = db[key]                # fetch by key, show in console
    except:
        print 'No such key "%s"!' % key
    else:
        for field in fieldnames:
            print field.ljust(maxfield), '=>', getattr(record, field)



ºìÉ«ÄÇÒ»ÐУ¬ÔÚpython2.3ÖÐÎÞ·¨ÔËÐУ¬2.4Ôò¿ÉÒÔ¡£ÕâÖмäÓÐʲô¸Ä½øºÍ±ä»¯£¿

-- --------------------------------------------
¶ÀÁ¢Ö®Ë¼Ï룬×ÔÓÉÖ®¾«Éñ¡£
                        --³ÂÒúã¡
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070109/932bb0b2/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年01月09日 星期二 17:18

yi huang yi.codeplayer在gmail.com
星期二 一月 9 17:18:04 HKT 2007

On 1/9/07, 适兕 <lijiangsheng1 at gmail.com> wrote:
>
> 如下代码
> import shelve
> fieldnames = ('name', 'age', 'job', 'pay')
> maxfield   =max(len(field) for field in fieldnames)
> db = shelve.open('class-shelve')
>
> while True:
>     key = raw_input('\nKey? => ')       # key or empty line, exc at eof
>     if not key: break
>     try:
>         record = db[key]                # fetch by key, show in console
>     except:
>         print 'No such key "%s"!' % key
>     else:
>         for field in fieldnames:
>             print field.ljust(maxfield), '=>', getattr(record, field)
>
>
>
> 红色那一行,在python2.3中无法运行,2.4则可以。这中间有什么改进和变化?
>
> -- --------------------------------------------
> 独立之思想,自由之精神。
>                         --陈寅恪
> _______________________________________________
> 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
>

generator expression

-- 
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070109/6cdda218/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号