2006年03月28日 星期二 21:51
def curry(*args, **kwargs): def _curried(*moreargs, **morekwargs): return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) return _curried >>> from django.utils.functional import curry >>> def a(a, b, c): ... print a, b, c >>> b = curry(a, 'a', 'b') >>> b('c') a b c 我一直认为函数是空的,怎么还可以作为对象放进去呢? 并且*args这样的形式不是接收元组吗? 接收函数是个怎么处理法? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060328/0879439a/attachment.html
2006年03月29日 星期三 00:53
curry是FP风格的东东,wiki上有详细的解释: http://en.wikipedia.org/wiki/Currying 在 06-3-28,风向标<vaneoooo at gmail.com> 写道: > > > def curry(*args, **kwargs): > def _curried(*moreargs, **morekwargs): > return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + > morekwargs.items())) > return _curried > > > >>> from django.utils.functional import curry > >>> def a(a, b, c): > ... print a, b, c > >>> b = curry(a, 'a', 'b') > >>> b('c') > a b c > > > 我一直认为函数是空的,怎么还可以作为对象放进去呢? > 并且*args这样的形式不是接收元组吗? > 接收函数是个怎么处理法? > _______________________________________________ > 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 > >
2006年03月29日 星期三 00:54
ibm上的这篇文章也提到了curry http://www-128.ibm.com/developerworks/linux/library/l-prog3.html 在 06-3-29,xxmplus<xxmplus at gmail.com> 写道: > curry是FP风格的东东,wiki上有详细的解释: > http://en.wikipedia.org/wiki/Currying > > 在 06-3-28,风向标<vaneoooo at gmail.com> 写道: > > > > > > def curry(*args, **kwargs): > > def _curried(*moreargs, **morekwargs): > > return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + > > morekwargs.items())) > > return _curried > > > > > > >>> from django.utils.functional import curry > > >>> def a(a, b, c): > > ... print a, b, c > > >>> b = curry(a, 'a', 'b') > > >>> b('c') > > a b c > > > > > > 我一直认为函数是空的,怎么还可以作为对象放进去呢? > > 并且*args这样的形式不是接收元组吗? > > 接收函数是个怎么处理法? > > _______________________________________________ > > 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 > > > > >
2006年03月29日 星期三 15:37
感谢xxmplus兄,wiki的上不了 ibm那个浏览了一下,看代码还勉强,不过内容读起来着实困难些 关于这样段代码: def curry(*args, **kwargs): def _curried(*moreargs, **morekwargs): return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) return _curried 不很理解的即是这样一部分,下面有: >>> def a(a, b, c): ... print a, b, c >>> b = curry(a, 'a', 'b') curry中第一个参数*args所接收的是一个函数,在其包含的函数_curride中,又有args[0]这样的句子,如果理解为一个元组我还可以理解,可是作为函数,通过args[0]访问到什么呢? 后面的又疑惑了,(*(args[1:]+morkargs),以及后面的内容,都是很困惑 还有,在函数嵌套函数中,例如_curried的参数是自动接收外函数所接收的? 即*args又传递到---------*moreargs??? _curried的参数又从何获取呢? 为这个郁闷了很久了,一直不解 在06-3-29,xxmplus <xxmplus at gmail.com> 写道: > > ibm上的这篇文章也提到了curry > http://www-128.ibm.com/developerworks/linux/library/l-prog3.html > > 在 06-3-29,xxmplus<xxmplus at gmail.com> 写道: > > curry是FP风格的东东,wiki上有详细的解释: > > http://en.wikipedia.org/wiki/Currying > > > > 在 06-3-28,风向标<vaneoooo at gmail.com> 写道: > > > > > > > > > def curry(*args, **kwargs): > > > def _curried(*moreargs, **morekwargs): > > > return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + > > > morekwargs.items())) > > > return _curried > > > > > > > > > >>> from django.utils.functional import curry > > > >>> def a(a, b, c): > > > ... print a, b, c > > > >>> b = curry(a, 'a', 'b') > > > >>> b('c') > > > a b c > > > > > > > > > 我一直认为函数是空的,怎么还可以作为对象放进去呢? > > > 并且*args这样的形式不是接收元组吗? > > > 接收函数是个怎么处理法? > > > _______________________________________________ > > > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060329/fe4cd969/attachment.html
2006年03月29日 星期三 16:02
对b = curry(a, 'a', 'b')而言 *args 接收的是 (a, 'a', 'b') 这样的tuple args[0]就是函数a本身, args[1:]就是 ('a','b') 所以返回的b实际上就是函数_curried 当调用b(10)的时候就等价于调用函数 a('a','b', 10) 不知道解释的清不清楚 ----- Original Message ----- From: 风向标 To: python-chinese at lists.python.cn Sent: Wednesday, March 29, 2006 3:37 PM Subject: Re: [python-chinese] 传送元组的*还可以放入函数? 感谢xxmplus兄,wiki的上不了 ibm那个浏览了一下,看代码还勉强,不过内容读起来着实困难些 关于这样段代码: def curry(*args, **kwargs): def _curried(*moreargs, **morekwargs): return args[0](*(args[1:]+moreargs), **dict( kwargs.items() + morekwargs.items())) return _curried 不很理解的即是这样一部分,下面有: >>> def a(a, b, c): ... print a, b, c >>> b = curry(a, 'a', 'b') curry中第一个参数*args所接收的是一个函数,在其包含的函数_curride中,又有args[0]这样的句子,如果理解为一个元组我还可以理解,可是作为函数,通过args[0]访问到什么呢? 后面的又疑惑了,(*(args[1:]+morkargs),以及后面的内容,都是很困惑 还有,在函数嵌套函数中,例如_curried的参数是自动接收外函数所接收的? 即*args又传递到---------*moreargs??? _curried的参数又从何获取呢? 为这个郁闷了很久了,一直不解 在06-3-29,xxmplus <xxmplus at gmail.com> 写道: ibm上的这篇文章也提到了curry http://www-128.ibm.com/developerworks/linux/library/l-prog3.html 在 06-3-29,xxmplus<xxmplus at gmail.com> 写道: > curry是FP风格的东东,wiki上有详细的解释: > http://en.wikipedia.org/wiki/Currying > > 在 06-3-28,风向标<vaneoooo at gmail.com> 写道: > > > > > > def curry(*args, **kwargs): > > def _curried(*moreargs, **morekwargs): > > return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + > > morekwargs.items())) > > return _curried > > > > > > >>> from django.utils.functional import curry > > >>> def a(a, b, c): > > ... print a, b, c > > >>> b = curry(a, 'a', 'b') > > >>> b('c') > > a b c > > > > > > 我一直认为函数是空的,怎么还可以作为对象放进去呢? > > 并且*args这样的形式不是接收元组吗? > > 接收函数是个怎么处理法? > > _______________________________________________ > > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060329/92fa7801/attachment.htm
2006年03月29日 星期三 16:06
b = curry(a, 'a', 'b')中, args[0]代表a,curry后生成新的函数b,不过已经把'a', 'b'绑定到b上了,你可以接着再绑;-} 至于_curried的参数?如果这样: c = curry(b, 'c', 'd','e') b(也就是 b = curry(a, 'a', 'b') 时的_curried)的参数是'c', 'd', 'e' 而现在c绑定了'a', 'b', 'c', 'd', 'e' ----- Original Message ----- From: 风向标 To: python-chinese at lists.python.cn Sent: Wednesday, March 29, 2006 3:37 PM Subject: Re: [python-chinese] 传送元组的*还可以放入函数? 感谢xxmplus兄,wiki的上不了 ibm那个浏览了一下,看代码还勉强,不过内容读起来着实困难些 关于这样段代码: def curry(*args, **kwargs): def _curried(*moreargs, **morekwargs): return args[0](*(args[1:]+moreargs), **dict( kwargs.items() + morekwargs.items())) return _curried 不很理解的即是这样一部分,下面有: >>> def a(a, b, c): ... print a, b, c >>> b = curry(a, 'a', 'b') curry中第一个参数*args所接收的是一个函数,在其包含的函数_curride中,又有args[0]这样的句子,如果理解为一个元组我还可以理解,可是作为函数,通过args[0]访问到什么呢? 后面的又疑惑了,(*(args[1:]+morkargs),以及后面的内容,都是很困惑 还有,在函数嵌套函数中,例如_curried的参数是自动接收外函数所接收的? 即*args又传递到---------*moreargs??? _curried的参数又从何获取呢? 为这个郁闷了很久了,一直不解 在06-3-29,xxmplus <xxmplus at gmail.com> 写道: ibm上的这篇文章也提到了curry http://www-128.ibm.com/developerworks/linux/library/l-prog3.html 在 06-3-29,xxmplus<xxmplus at gmail.com> 写道: > curry是FP风格的东东,wiki上有详细的解释: > http://en.wikipedia.org/wiki/Currying > > 在 06-3-28,风向标<vaneoooo at gmail.com> 写道: > > > > > > def curry(*args, **kwargs): > > def _curried(*moreargs, **morekwargs): > > return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + > > morekwargs.items())) > > return _curried > > > > > > >>> from django.utils.functional import curry > > >>> def a(a, b, c): > > ... print a, b, c > > >>> b = curry(a, 'a', 'b') > > >>> b('c') > > a b c > > > > > > 我一直认为函数是空的,怎么还可以作为对象放进去呢? > > 并且*args这样的形式不是接收元组吗? > > 接收函数是个怎么处理法? > > _______________________________________________ > > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060329/f8d4944b/attachment-0001.html
2006年03月29日 星期三 17:18
wiki不是说解禁了么,还是不能访问么 在 06-3-29,Slowness Chen<chenzh at bhh.com.cn> 写道: > > b = curry(a, 'a', 'b')中, > > args[0]代表a,curry后生成新的函数b,不过已经把'a', 'b'绑定到b上了,你可以接着再绑;-} > > > 至于_curried的参数?如果这样: > > c = curry(b, 'c', 'd','e') > > b(也就是 b = curry(a, 'a', 'b') 时的_curried)的参数是'c', 'd', 'e' > > 而现在c绑定了'a', 'b', 'c', 'd', 'e' > > ----- Original Message ----- > From: 风向标 > To: python-chinese at lists.python.cn > Sent: Wednesday, March 29, 2006 3:37 PM > Subject: Re: [python-chinese] 传送元组的*还可以放入函数? > > > > > 感谢xxmplus兄,wiki的上不了 > ibm那个浏览了一下,看代码还勉强,不过内容读起来着实困难些 > > 关于这样段代码: > > def curry(*args, **kwargs): > def _curried(*moreargs, **morekwargs): > return args[0](*(args[1:]+moreargs), **dict( kwargs.items() + > morekwargs.items())) > return _curried > > 不很理解的即是这样一部分,下面有: > > >>> def a(a, b, c): > ... print a, b, c > >>> b = curry(a, 'a', 'b') > > curry中第一个参数*args所接收的是一个函数,在其包含的函数_curride中,又有args[0]这样的句子,如果理解为一个元组我还可以理解,可是作为函数,通过args[0]访问到什么呢? > > 后面的又疑惑了,(*(args[1:]+morkargs),以及后面的内容,都是很困惑 > 还有,在函数嵌套函数中,例如_curried的参数是自动接收外函数所接收的? > 即*args又传递到---------*moreargs??? > _curried的参数又从何获取呢? > > 为这个郁闷了很久了,一直不解 > > 在06-3-29,xxmplus <xxmplus at gmail.com> 写道: > > ibm上的这篇文章也提到了curry > > > http://www-128.ibm.com/developerworks/linux/library/l-prog3.html > > > > 在 06-3-29,xxmplus<xxmplus at gmail.com> 写道: > > > curry是FP风格的东东,wiki上有详细的解释: > > > http://en.wikipedia.org/wiki/Currying > > > > > > 在 06-3-28,风向标<vaneoooo at gmail.com> 写道: > > > > > > > > > > > > def curry(*args, **kwargs): > > > > def _curried(*moreargs, **morekwargs): > > > > return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + > > > > morekwargs.items())) > > > > return _curried > > > > > > > > > > > > >>> from django.utils.functional import curry > > > > >>> def a(a, b, c): > > > > ... print a, b, c > > > > >>> b = curry(a, 'a', 'b') > > > > >>> b('c') > > > > a b c > > > > > > > > > > > > 我一直认为函数是空的,怎么还可以作为对象放进去呢? > > > > 并且*args这样的形式不是接收元组吗? > > > > 接收函数是个怎么处理法? > > > > _______________________________________________ > > > > 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 > > > > _______________________________________________ > 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 > >
2006年03月29日 星期三 17:30
好象能理解了! 感谢解答问题的yi yang兄、xxmplus兄、slowness chen兄 以及chris兄 我想我需要多动手用一用才能更深刻的理解 谢谢! 在06-3-29,xxmplus <xxmplus at gmail.com> 写道: > wiki不是说解禁了么,还是不能访问么 > > 在 06-3-29,Slowness Chen<chenzh at bhh.com.cn> 写道: > > > > b = curry(a, 'a', 'b')中, > > > > args[0]代表a,curry后生成新的函数b,不过已经把'a', 'b'绑定到b上了,你可以接着再绑;-} > > > > > > 至于_curried的参数?如果这样: > > > > c = curry(b, 'c', 'd','e') > > > > b(也就是 b = curry(a, 'a', 'b') 时的_curried)的参数是'c', 'd', 'e' > > > > 而现在c绑定了'a', 'b', 'c', 'd', 'e' > > > > ----- Original Message ----- > > From: 风向标 > > To: python-chinese at lists.python.cn > > Sent: Wednesday, March 29, 2006 3:37 PM > > Subject: Re: [python-chinese] 传送元组的*还可以放入函数? > > > > > > > > > > 感谢xxmplus兄,wiki的上不了 > > ibm那个浏览了一下,看代码还勉强,不过内容读起来着实困难些 > > > > 关于这样段代码: > > > > def curry(*args, **kwargs): > > def _curried(*moreargs, **morekwargs): > > return args[0](*(args[1:]+moreargs), **dict( kwargs.items() + > > morekwargs.items())) > > return _curried > > > > 不很理解的即是这样一部分,下面有: > > > > >>> def a(a, b, c): > > ... print a, b, c > > >>> b = curry(a, 'a', 'b') > > > > > curry中第一个参数*args所接收的是一个函数,在其包含的函数_curride中,又有args[0]这样的句子,如果理解为一个元组我还可以理解,可是作为函数,通过args[0]访问到什么呢? > > > > 后面的又疑惑了,(*(args[1:]+morkargs),以及后面的内容,都是很困惑 > > 还有,在函数嵌套函数中,例如_curried的参数是自动接收外函数所接收的? > > 即*args又传递到---------*moreargs??? > > _curried的参数又从何获取呢? > > > > 为这个郁闷了很久了,一直不解 > > > > 在06-3-29,xxmplus <xxmplus at gmail.com> 写道: > > > ibm上的这篇文章也提到了curry > > > > > http://www-128.ibm.com/developerworks/linux/library/l-prog3.html > > > > > > 在 06-3-29,xxmplus<xxmplus at gmail.com> 写道: > > > > curry是FP风格的东东,wiki上有详细的解释: > > > > http://en.wikipedia.org/wiki/Currying > > > > > > > > 在 06-3-28,风向标<vaneoooo at gmail.com> 写道: > > > > > > > > > > > > > > > def curry(*args, **kwargs): > > > > > def _curried(*moreargs, **morekwargs): > > > > > return args[0](*(args[1:]+moreargs), **dict(kwargs.items() > + > > > > > morekwargs.items())) > > > > > return _curried > > > > > > > > > > > > > > > >>> from django.utils.functional import curry > > > > > >>> def a(a, b, c): > > > > > ... print a, b, c > > > > > >>> b = curry(a, 'a', 'b') > > > > > >>> b('c') > > > > > a b c > > > > > > > > > > > > > > > 我一直认为函数是空的,怎么还可以作为对象放进去呢? > > > > > 并且*args这样的形式不是接收元组吗? > > > > > 接收函数是个怎么处理法? > > > > > _______________________________________________ > > > > > 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 > > > > > > > > _______________________________________________ > > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060329/5f6ebe96/attachment.html
Zeuux © 2025
京ICP备05028076号