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/2005-August/055510.html below:

[Python-Dev] PEP 309: Partial method application

[Python-Dev] PEP 309: Partial method applicationJosiah Carlson jcarlson at uci.edu
Fri Aug 19 02:09:09 CEST 2005
Steven Bethard <steven.bethard at gmail.com> wrote:
> 
> Martin v. Löwis wrote:
> > So I would propose the syntax
> >
> >   lst.sort(key=virtual.lower) # where virtual is functional.virtual
>  
> Shane Hathaway wrote:
> > class virtual:
> >      def __getattr__(self, name):
> >          return lambda obj: getattr(obj, name)()
> > virtual = virtual()
> 
> I think (perhaps because of the name) that this could be confusing.  I
> don't have any intuition that "virtual.lower" would return a function
> that calls the "lower" attribute instead of returning a function that
> simply accesses that attribute.
> 
> If we're going to move away from the itemgetter() and attrgetter()
> style, then we should be consistent about it and provide a solution
> (or solutions) that answers all of these problems:
>     obj.attr
>     obj.attr(*args, **kwargs)
>     obj[key]
> I'm not sure that there is a clean/obvious way to do this.

I thought that:
  operator.attrgetter() was for obj.attr
  operator.itemgetter() was for obj[integer_index]

That's almost all the way there.  All that remains is to have something
that gets any key (not just integers) and which handles function calls.

In terms of the function call semantics, what about:

   class methodcall:
       def __getattr__(self, name, *args, **kwds):
           def delayedcall(obj):
               return getattr(obj, name)(*args, **kwds)
           return delayedcall
   methodcall = methodcall()

 - Josiah

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