Python论坛  - 讨论区

标题:[python-chinese] 请问有没有语句能一次性转换字典里的编码

2007年05月09日 星期三 17:29

ro rosettas在gmail.com
星期三 五月 9 17:29:42 HKT 2007

hi all

就是想把一个字典里面所有的的unicode串转成utf8,不知道是否有这样的函数

-- 
with kind regards

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

2007年05月09日 星期三 17:47

刘鑫 march.liu在gmail.com
星期三 五月 9 17:47:13 HKT 2007

×Ô¼ºÐ´Ò»¸öËƺõºÜÈÝÒ×

def encode_dict(d):
    def helpler():
        for k in d:
            yield (k, d[k].encode('utf-8'))

   return dict(helper(d))

2007/5/9, ro <rosettas在gmail.com>:
>
> hi all
>
> ¾ÍÊÇÏë°ÑÒ»¸ö×ÖµäÀïÃæËùÓеĵÄunicode´®×ª³Éutf8,²»ÖªµÀÊÇ·ñÓÐÕâÑùµÄº¯Êý
>
> --
> with kind regards
> _______________________________________________
> 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




-- 
µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï

ÁõöÎ
March.Liu
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070509/893a9452/attachment.htm 

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

2007年05月09日 星期三 18:21

Rodin schludern在gmail.com
星期三 五月 9 18:21:07 HKT 2007

def encode_dict(d):
    def helpler():
        for k in d:
            yield (k, d[k].encode('utf-8'))

   return dict(helper(d))
                            ^
纠正大侠一个错误:return dict(helper())

在 07-5-9,刘鑫<march.liu在gmail.com> 写道:
> 自己写一个似乎很容易
>
> def encode_dict(d):
>     def helpler():
>         for k in d:
>             yield (k, d[k].encode('utf-8'))
>
>    return dict(helper(d))
>
> 2007/5/9, ro < rosettas在gmail.com>:
> > hi all
> >
> > 就是想把一个字典里面所有的的unicode串转成utf8,不知道是否有这样的函数
> >
> > --
> > with kind regards
> > _______________________________________________
> > 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
>
>
>
> --
> 登山者去登山,因为山在那里
> 我在思考,因为问题在那里
>
> 刘鑫
> March.Liu
> _______________________________________________
> 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
>

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

2007年05月09日 星期三 18:24

Rodin schludern在gmail.com
星期三 五月 9 18:24:40 HKT 2007

顺便请教:yield的含义和用法
英语不咋样,Python Manual里的yield stmt 没看懂 -_-!!

我在命令行中执行的时候,没有放在函数内直接 yield 了,发生异常:

SyntaxError: 'yield' outside function

这个必须放在函数体内执行么?

在 07-5-9,Rodin<schludern在gmail.com> 写道:
> def encode_dict(d):
>    def helpler():
>        for k in d:
>            yield (k, d[k].encode('utf-8'))
>
>   return dict(helper(d))
>                            ^
> 纠正大侠一个错误:return dict(helper())
>
> 在 07-5-9,刘鑫<march.liu在gmail.com> 写道:
> > 自己写一个似乎很容易
> >
> > def encode_dict(d):
> >     def helpler():
> >         for k in d:
> >             yield (k, d[k].encode('utf-8'))
> >
> >    return dict(helper(d))
> >
> > 2007/5/9, ro < rosettas在gmail.com>:
> > > hi all
> > >
> > > 就是想把一个字典里面所有的的unicode串转成utf8,不知道是否有这样的函数
> > >
> > > --
> > > with kind regards
> > > _______________________________________________
> > > 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
> >
> >
> >
> > --
> > 登山者去登山,因为山在那里
> > 我在思考,因为问题在那里
> >
> > 刘鑫
> > March.Liu
> > _______________________________________________
> > 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
> >
>

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

2007年05月09日 星期三 18:30

nicran在gmail.com nicran在gmail.com
星期三 五月 9 18:30:50 HKT 2007

you can read the doc of myhdl package to get a better understanding of 'yield'

Sent from my BlackBerry® wireless handheld  

-----Original Message-----
From: Rodin <schludern在gmail.com>
Date: Wed, 9 May 2007 18:24:40 
To:python-chinese在lists.python.cn
Subject: Re: [python-chinese]
	请问有没有语句能一次性转换
	字典里的编码

顺便请教:yield的含义和用法
英语不咋样,Python Manual里的yield stmt 没看懂 -_-!!

我在命令行中执行的时候,没有放在函数内直接 yield 了,发生异常:

SyntaxError: 'yield' outside function

这个必须放在函数体内执行么?

在 07-5-9,Rodin<schludern在gmail.com> 写道:
> def encode_dict(d):
>    def helpler():
>        for k in d:
>            yield (k, d[k].encode('utf-8'))
>
>   return dict(helper(d))
>                            ^
> 纠正大侠一个错误:return dict(helper())
>
> 在 07-5-9,刘鑫<march.liu在gmail.com> 写道:
> > 自己写一个似乎很容易
> >
> > def encode_dict(d):
> >     def helpler():
> >         for k in d:
> >             yield (k, d[k].encode('utf-8'))
> >
> >    return dict(helper(d))
> >
> > 2007/5/9, ro < rosettas在gmail.com>:
> > > hi all
> > >
> > > 就是想把一个字典里面所有的的unicode串转成utf8,不知道是否有这样的函数
> > >
> > > --
> > > with kind regards
> > > _______________________________________________
> > > 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
> >
> >
> >
> > --
> > 登山者去登山,因为山在那里
> > 我在思考,因为问题在那里
> >
> > 刘鑫
> > March.Liu
> > _______________________________________________
> > 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

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

2007年05月09日 星期三 18:34

刘鑫 march.liu在gmail.com
星期三 五月 9 18:34:38 HKT 2007

ûµ÷ÊÔ¾ÍÕæ½ÓдÉÏÈ¥£¬¼ûЦÁË¡£
yieldÔÚpython
tutorialÀïÓÐʹÓýéÉÜ£¬°´ÎÄÖеĽéÉÜ£¬yield×î³õÊÇÉè¼ÆÀ´¼ò»¯µü´ú¶ÔÏóµÄ¹¹Ôì¡£ÔÚÀíÂÛÉÏËüÒ²ÓÐһЩ±È½ÏÉî²ã´ÎµÄº¬Ò壬²»¹ýÕâ·½Ãæ¾Í³¬³öÎÒµÄÄÜÁ¦ÁË:P

ÔÚ07-5-9£¬Rodin <schludern在gmail.com> дµÀ£º
>
> ˳±ãÇë½Ì£ºyieldµÄº¬ÒåºÍÓ÷¨
> Ó¢Óï²»Õ¦Ñù£¬Python ManualÀïµÄyield stmt û¿´¶® -_-!!
>
> ÎÒÔÚÃüÁîÐÐÖÐÖ´ÐеÄʱºò£¬Ã»ÓзÅÔÚº¯ÊýÄÚÖ±½Ó yield ÁË£¬·¢ÉúÒì³££º
>
> SyntaxError: 'yield' outside function
>
> Õâ¸ö±ØÐë·ÅÔÚº¯ÊýÌåÄÚÖ´ÐÐô£¿
>
> ÔÚ 07-5-9£¬Rodin<schludern在gmail.com> дµÀ£º
> > def encode_dict(d):
> >    def helpler():
> >        for k in d:
> >            yield (k, d[k].encode('utf-8'))
> >
> >   return dict(helper(d))
> >                            ^
> > ¾ÀÕý´óÏÀÒ»¸ö´íÎó£ºreturn dict(helper())
> >
> > ÔÚ 07-5-9£¬ÁõöÎ<march.liu在gmail.com> дµÀ£º
> > > ×Ô¼ºÐ´Ò»¸öËƺõºÜÈÝÒ×
> > >
> > > def encode_dict(d):
> > >     def helpler():
> > >         for k in d:
> > >             yield (k, d[k].encode('utf-8'))
> > >
> > >    return dict(helper(d))
> > >
> > > 2007/5/9, ro < rosettas在gmail.com>:
> > > > hi all
> > > >
> > > > ¾ÍÊÇÏë°ÑÒ»¸ö×ÖµäÀïÃæËùÓеĵÄunicode´®×ª³Éutf8,²»ÖªµÀÊÇ·ñÓÐÕâÑùµÄº¯Êý
> > > >
> > > > --
> > > > with kind regards
> > > > _______________________________________________
> > > > 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
> > >
> > >
> > >
> > > --
> > > µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
> > > ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï
> > >
> > > ÁõöÎ
> > > March.Liu
> > > _______________________________________________
> > > 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




-- 
µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï

ÁõöÎ
March.Liu
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070509/513e49a3/attachment-0001.htm 

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

2007年05月09日 星期三 18:48

Rodin schludern在gmail.com
星期三 五月 9 18:48:08 HKT 2007

谢谢

刚刚理解 yield 是产生了一个可迭代的对象 ^_^
如果没有yield的话,上面那个这样写也是可以的吧:

>>> def encode_dict(d):
...     for k in d:
...             d[k]=d[k].encode('utf-8')
...     return d

在 07-5-9,刘鑫<march.liu在gmail.com> 写道:
> 没调试就真接写上去,见笑了。
> yield在python
> tutorial里有使用介绍,按文中的介绍,yield最初是设计来简化迭代对象的构造。在理论上它也有一些比较深层次的含义,不过这方面就超出我的能力了:P
>
> 在07-5-9,Rodin < schludern在gmail.com> 写道:
> >
> > 顺便请教:yield的含义和用法
> > 英语不咋样,Python Manual里的yield stmt 没看懂 -_-!!
> >
> > 我在命令行中执行的时候,没有放在函数内直接 yield 了,发生异常:
> >
> > SyntaxError: 'yield' outside function
> >
> > 这个必须放在函数体内执行么?
> >
> > 在 07-5-9,Rodin<schludern在gmail.com> 写道:
> > > def encode_dict(d):
> > >    def helpler():
> > >        for k in d:
> > >            yield (k, d[k].encode('utf-8'))
> > >
> > >   return dict(helper(d))
> > >                            ^
> > > 纠正大侠一个错误:return dict(helper())
> > >
> > > 在 07-5-9,刘鑫<march.liu在gmail.com> 写道:
> > > > 自己写一个似乎很容易
> > > >
> > > > def encode_dict(d):
> > > >     def helpler():
> > > >         for k in d:
> > > >             yield (k, d[k].encode('utf-8'))
> > > >
> > > >    return dict(helper(d))
> > > >
> > > > 2007/5/9, ro < rosettas在gmail.com>:
> > > > > hi all
> > > > >
> > > > > 就是想把一个字典里面所有的的unicode串转成utf8,不知道是否有这样的函数
> > > > >
> > > > > --
> > > > > with kind regards
> > > > > _______________________________________________
> > > > > 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
> > > >
> > > >
> > > >
> > > > --
> > > > 登山者去登山,因为山在那里
> > > > 我在思考,因为问题在那里
> > > >
> > > > 刘鑫
> > > > March.Liu
> > > > _______________________________________________
> > > > 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
>
>
>
> --
> 登山者去登山,因为山在那里
> 我在思考,因为问题在那里
>
> 刘鑫
> March.Liu
> _______________________________________________
> 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
>

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

2007年05月09日 星期三 18:52

黄毅 yi.codeplayer在gmail.com
星期三 五月 9 18:52:29 HKT 2007

>
> 谢谢
>
> 刚刚理解 yield 是产生了一个可迭代的对象 ^_^
> 如果没有yield的话,上面那个这样写也是可以的吧:
>
> >>> def encode_dict(d):
> ...     for k in d:
> ...             d[k]=d[k].encode('utf-8')
> ...     return d


刘兄的方法是产生一个新的 dict, 你是直接修改传入的 dict ,都不错,不过你这个就没必要再返回这个 dict 了,会让人误会的。

-- 
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070509/8b29f6ce/attachment.html 

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

2007年05月09日 星期三 18:54

刘鑫 march.liu在gmail.com
星期三 五月 9 18:54:33 HKT 2007

ÊÇ°¡£¬¸Ð¾õÕâÑùд¸üºÃһЩ£¬¸Õ²ÅÎÒÓÐЩ¾À²øÓï·¨ÁË£º£©

ÔÚ07-5-9£¬Rodin <schludern在gmail.com> дµÀ£º
>
> лл
>
> ¸Õ¸ÕÀí½â yield ÊDzúÉúÁËÒ»¸ö¿Éµü´úµÄ¶ÔÏó ^_^
> Èç¹ûûÓÐyieldµÄ»°£¬ÉÏÃæÄǸöÕâÑùдҲÊÇ¿ÉÒԵİɣº
>
> >>> def encode_dict(d):
> ...     for k in d:
> ...             d[k]=d[k].encode('utf-8')
> ...     return d
>
> ÔÚ 07-5-9£¬ÁõöÎ<march.liu在gmail.com> дµÀ£º
> > ûµ÷ÊÔ¾ÍÕæ½ÓдÉÏÈ¥£¬¼ûЦÁË¡£
> > yieldÔÚpython
> >
> tutorialÀïÓÐʹÓýéÉÜ£¬°´ÎÄÖеĽéÉÜ£¬yield×î³õÊÇÉè¼ÆÀ´¼ò»¯µü´ú¶ÔÏóµÄ¹¹Ôì¡£ÔÚÀíÂÛÉÏËüÒ²ÓÐһЩ±È½ÏÉî²ã´ÎµÄº¬Ò壬²»¹ýÕâ·½Ãæ¾Í³¬³öÎÒµÄÄÜÁ¦ÁË:P
> >
> > ÔÚ07-5-9£¬Rodin < schludern在gmail.com> дµÀ£º
> > >
> > > ˳±ãÇë½Ì£ºyieldµÄº¬ÒåºÍÓ÷¨
> > > Ó¢Óï²»Õ¦Ñù£¬Python ManualÀïµÄyield stmt û¿´¶® -_-!!
> > >
> > > ÎÒÔÚÃüÁîÐÐÖÐÖ´ÐеÄʱºò£¬Ã»ÓзÅÔÚº¯ÊýÄÚÖ±½Ó yield ÁË£¬·¢ÉúÒì³££º
> > >
> > > SyntaxError: 'yield' outside function
> > >
> > > Õâ¸ö±ØÐë·ÅÔÚº¯ÊýÌåÄÚÖ´ÐÐô£¿
> > >
> > > ÔÚ 07-5-9£¬Rodin<schludern在gmail.com> дµÀ£º
> > > > def encode_dict(d):
> > > >    def helpler():
> > > >        for k in d:
> > > >            yield (k, d[k].encode('utf-8'))
> > > >
> > > >   return dict(helper(d))
> > > >                            ^
> > > > ¾ÀÕý´óÏÀÒ»¸ö´íÎó£ºreturn dict(helper())
> > > >
> > > > ÔÚ 07-5-9£¬ÁõöÎ<march.liu在gmail.com> дµÀ£º
> > > > > ×Ô¼ºÐ´Ò»¸öËƺõºÜÈÝÒ×
> > > > >
> > > > > def encode_dict(d):
> > > > >     def helpler():
> > > > >         for k in d:
> > > > >             yield (k, d[k].encode('utf-8'))
> > > > >
> > > > >    return dict(helper(d))
> > > > >
> > > > > 2007/5/9, ro < rosettas在gmail.com>:
> > > > > > hi all
> > > > > >
> > > > > > ¾ÍÊÇÏë°ÑÒ»¸ö×ÖµäÀïÃæËùÓеĵÄunicode´®×ª³Éutf8,²»ÖªµÀÊÇ·ñÓÐÕâÑùµÄº¯Êý
> > > > > >
> > > > > > --
> > > > > > with kind regards
> > > > > > _______________________________________________
> > > > > > 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
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
> > > > > ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï
> > > > >
> > > > > ÁõöÎ
> > > > > March.Liu
> > > > > _______________________________________________
> > > > > 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
> >
> >
> >
> > --
> > µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
> > ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï
> >
> > ÁõöÎ
> > March.Liu
> > _______________________________________________
> > 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




-- 
µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï

ÁõöÎ
March.Liu
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070509/f472df23/attachment.html 

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

2007年05月09日 星期三 19:00

刘鑫 march.liu在gmail.com
星期三 五月 9 19:00:46 HKT 2007

Èç¹û²»Ï£ÍûÐÞ¸ÄÔ­À´×ֵ䣬¸É´àÕâÑù£º

encode_dict = lambda d : dict((k, d[k].encode('utf-8') ) for k in d)

È»ºóµ÷ÓÃencode_dictº¯Êý¾Í¿ÉÒÔ¡£

½ñÌìÓÐЩÐIJ»ÔÚÑÉ£¬²»ºÃÒâ˼£¬±¾ÒâÊÇÏëдÕâôһ¸ö¶«Î÷µÄ¡£

ÔÚ07-5-9£¬»ÆÒã <yi.codeplayer在gmail.com> дµÀ£º
>
> лл
> >
> > ¸Õ¸ÕÀí½â yield ÊDzúÉúÁËÒ»¸ö¿Éµü´úµÄ¶ÔÏó ^_^
> > Èç¹ûûÓÐyieldµÄ»°£¬ÉÏÃæÄǸöÕâÑùдҲÊÇ¿ÉÒԵİɣº
> >
> > >>> def encode_dict(d):
> > ...     for k in d:
> > ...             d[k]=d[k].encode('utf-8')
> > ...     return d
>
>
> ÁõÐֵķ½·¨ÊDzúÉúÒ»¸öÐ嵀 dict£¬ ÄãÊÇÖ±½ÓÐ޸Ĵ«ÈëµÄ dict £¬¶¼²»´í£¬²»¹ýÄãÕâ¸ö¾Íû±ØÒªÔÙ·µ»ØÕâ¸ö dict ÁË£¬»áÈÃÈËÎó»áµÄ¡£
>
> --
> http://codeplayer.blogspot.com/
>
> _______________________________________________
> 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
>



-- 
µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï

ÁõöÎ
March.Liu
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070509/237f3ebf/attachment-0001.htm 

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

2007年05月10日 星期四 08:51

3751 lwm3751在gmail.com
星期四 五月 10 08:51:17 HKT 2007

我觉得写成这个样子会比较好一点
encode_dict = lambda d : dict((k, v.encode('utf-8') ) for k, v in
d.iteritems())
d[k]似乎会多查找一次字典。
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070510/8f3a1484/attachment.html 

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

2007年05月10日 星期四 09:09

wyh wyhross在gmail.com
星期四 五月 10 09:09:59 HKT 2007

¸öÈËÀí½â£¬yield ʵÏÖÁ˺¯ÊýÖжϣ¡




wyh
2007-05-10



·¢¼þÈË£º Rodin
·¢ËÍʱ¼ä£º 2007-05-09 18:23:20
ÊÕ¼þÈË£º python-chinese在lists.python.cn
³­ËÍ£º 
Ö÷Ì⣺ Re: [python-chinese]ÇëÎÊÓÐûÓÐÓï¾äÄÜÒ»´ÎÐÔת»»×ÖµäÀïµÄ±àÂë

def  encode_dict(d):
       def  helpler():
               for  k  in  d:
                       yield  (k,  d[k].encode('utf-8'))

     return  dict(helper(d))
                                                       ^
¾ÀÕý´óÏÀÒ»¸ö´íÎó£ºreturn  dict(helper())

ÔÚ  07-5-9£¬ÁõöÎ <march.liu在gmail.com >  дµÀ£º
>  ×Ô¼ºÐ´Ò»¸öËƺõºÜÈÝÒ×
>
>  def  encode_dict(d):
>          def  helpler():
>                  for  k  in  d:
>                          yield  (k,  d[k].encode('utf-8'))
>
>        return  dict(helper(d))
>
>  2007/5/9,  ro   <  rosettas在gmail.com >:
>   >  hi  all
>   >
>   >  ¾ÍÊÇÏë°ÑÒ»¸ö×ÖµäÀïÃæËùÓеĵÄunicode´®×ª³Éutf8,²»ÖªµÀÊÇ·ñÓÐÕâÑùµÄº¯Êý
>   >
>   >  --
>   >  with  kind  regards
>   >  _______________________________________________
>   >  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
>
>
>
>  --
>  µÇɽÕßÈ¥µÇɽ£¬ÒòΪɽÔÚÄÇÀï
>  ÎÒÔÚ˼¿¼£¬ÒòΪÎÊÌâÔÚÄÇÀï
>
>  ÁõöÎ
>  March.Liu
>  _______________________________________________
>  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/20070510/7221f026/attachment.html 

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

2007年05月10日 星期四 09:12

limodou limodou在gmail.com
星期四 五月 10 09:12:43 HKT 2007

On 5/10/07, wyh <wyhross在gmail.com> wrote:
>
>
> 个人理解,yield 实现了函数中断!
>
列表中有以前关于yield的一些讨论,可以找一找。

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

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

2007年05月10日 星期四 09:24

Rodin schludern在gmail.com
星期四 五月 10 09:24:31 HKT 2007

谢谢各位大侠,小弟对yield有一些粗浅的认识了 ^_^

2007/5/10, limodou <limodou在gmail.com>:
> On 5/10/07, wyh <wyhross在gmail.com> wrote:
> >
> >
> > 个人理解,yield 实现了函数中断!
> >
> 列表中有以前关于yield的一些讨论,可以找一找。
>
> --
> I like python!
> UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
> My Blog: http://www.donews.net/limodou
> _______________________________________________
> 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

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号