A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2007-November/075309.html below:

[Python-Dev] Should we do away with unbound methods in Py3k?

[Python-Dev] Should we do away with unbound methods in Py3k? [Python-Dev] Should we do away with unbound methods in Py3k?Phillip J. Eby pje at telecommunity.com
Fri Nov 23 14:04:32 CET 2007
At 07:57 PM 11/23/2007 +1300, Greg Ewing wrote:
>Phillip J. Eby wrote:
>>If you are configuring it per-class and accessing it per-instance, 
>>and reusing an existing function, you have to make it a staticmethod.
>
>I don't understand that. Can you provide an example?


def two_decimal_places(text):
     # ...

class Field:
     # doesn't need staticmethod because str isn't a function
     converter = str

     def __init__(self, title):
         self.title = title


class MoneyField(Field):
     # does need staticmethod because two_decimal_places
     # doesn't take a self
     converter = staticmethod(two_decimal_places)


def get_input(field):
     return field.converter(raw_input(field.title+': '))


>> > some subclasser later finds that he wants access to
>> > 'self'?
>>Then he overrides it with a normal method.
>
>If that works, I don't see why making the default
>method a normal method wouldn't work also.

Because sometimes you want to reuse an existing function, as shown above.

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