A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-February/070879.html below:

[Python-Dev] Shortcut Notation for Chaining Method Calls

[Python-Dev] Shortcut Notation for Chaining Method Calls [Python-Dev] Shortcut Notation for Chaining Method CallsMichael Foord fuzzyman at voidspace.org.uk
Sun Feb 4 00:30:57 CET 2007
Greg Ewing wrote:
> Michael O'Keefe wrote:
>   
>> I'd like to see a built-in shorthand to allow me to 
>> chain method calls even when a method call does not explicity 
>> return a reference to the instance of the object (self).
>>     
>
>   
>> def newFunc02():
>>     return NewList([8,9,7,1]).self_('sort').self_('reverse').self_('pop',0)
>>     
>
> My thought is that you're trying to write programs
> in some other language using Python.
>
> If you really want all that on one line, you can
> do it already:
>
>    x = NewList([8,9,7,1]); x.sort(); x.reverse(); return x.pop(0)
>
> which is just as compact and doesn't suffer from
> the weirdness of passing method names in as quoted
> strings.
>   
You could write a metaclass which decorates all methods in a class.  Any 
methods which return None could return self instead.

Michael

> --
> Greg
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
>
>
>   

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4