Python论坛  - 讨论区

标题:[python-chinese] lambda: None 如何解释?

2005年07月07日 星期四 15:17

Person person.lee at gmail.com
Thu Jul 7 15:17:23 HKT 2005

看到SQLStorage.py有如下函数:
getattr(aq_parent, 'UID', lambda: None)()
请问如何解释?

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

2005年07月07日 星期四 15:24

limodou limodou at gmail.com
Thu Jul 7 15:24:55 HKT 2005

好象是从aq_parent从查找UID方法,如果没找到返回lambda(不过有些怪没有试),然后执行,因为后面有()

在 05-7-7,Person<person.lee at gmail.com> 写道:
> 看到SQLStorage.py有如下函数:
> getattr(aq_parent, 'UID', lambda: None)()
> 请问如何解释?
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
> 


-- 
I like python! 
My Donews Blog: http://www.donews.net/limodou
New Google Maillist: http://groups-beta.google.com/group/python-cn

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

2005年07月07日 星期四 16:02

Qiangning Hong hongqn at gmail.com
Thu Jul 7 16:02:13 HKT 2005

其实就相当于

try:
  aq_parent.UID()
except AttributeError:
  pass

lambda: None 就是一个返回None的函数


On 7/7/05, limodou <limodou at gmail.com> wrote:
> 好象是从aq_parent从查找UID方法,如果没找到返回lambda(不过有些怪没有试),然后执行,因为后面有()
> 
> 在 05-7-7,Person<person.lee at gmail.com> 写道:
> > 看到SQLStorage.py有如下函数:
> > getattr(aq_parent, 'UID', lambda: None)()
> > 请问如何解释?
> >
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
> 
> 
> --
> I like python!
> My Donews Blog: http://www.donews.net/limodou
> New Google Maillist: http://groups-beta.google.com/group/python-cn
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
> 


-- 
Qiangning Hong

I'm usually annoyed by IDEs because, for instance, they don't use VIM
as an editor. Since I'm hooked to that, all IDEs I've used so far have
failed to impress me.
   -- Sybren Stuvel @ c.l.python

Get Firefox! <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>

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

2005年07月08日 星期五 16:43

Person person.lee at gmail.com
Fri Jul 8 16:43:09 HKT 2005

lambda:None就是一个返回None的函数,确实如此:
>>> f = lambda:None
>>> print f()
None

谢谢!
在 05-7-7,Qiangning Hong<hongqn at gmail.com> 写道:
> 其实就相当于
> 
> try:
>  aq_parent.UID()
> except AttributeError:
>  pass
> 
> lambda: None 就是一个返回None的函数
> 
> 
> On 7/7/05, limodou <limodou at gmail.com> wrote:
> > 好象是从aq_parent从查找UID方法,如果没找到返回lambda(不过有些怪没有试),然后执行,因为后面有()
> >
> > 在 05-7-7,Person<person.lee at gmail.com> 写道:
> > > 看到SQLStorage.py有如下函数:
> > > getattr(aq_parent, 'UID', lambda: None)()
> > > 请问如何解释?
> > >
> > > _______________________________________________
> > > python-chinese list
> > > python-chinese at lists.python.cn
> > > http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> > >
> >
> >
> > --
> > I like python!
> > My Donews Blog: http://www.donews.net/limodou
> > New Google Maillist: http://groups-beta.google.com/group/python-cn
> >
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
> 
> 
> --
> Qiangning Hong
> 
> I'm usually annoyed by IDEs because, for instance, they don't use VIM
> as an editor. Since I'm hooked to that, all IDEs I've used so far have
> failed to impress me.
>   -- Sybren Stuvel @ c.l.python
> 
> Get Firefox! <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
>

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号