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-October/075058.html below:

[Python-Dev] Declaring setters with getters

[Python-Dev] Declaring setters with getters [Python-Dev] Declaring setters with gettersskip at pobox.com skip at pobox.com
Wed Oct 31 18:48:13 CET 2007
    Guido> I've come up with a relatively unobtrusive pattern for defining
    Guido> setters. Given the following definition:

    ...

I'm a pretty naive user of properties, so can you explain to me how what you
propose is better than

    class C(object):
        def __init__(self):
            self._encoding = None

        def get_encoding(self):
            return self._encoding

        def set_encoding(self, value):
            if value is not None:
                unicode("0", value)  # Test it
            self._encoding = value
        encoding = property(get_encoding, set_encoding)

?

    Guido> I'd also like to change property so that the doc string defaults
    Guido> to the doc string of the getter.

How about defaulting it to the first argument to property() which has a doc
string?

Skip
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