Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9067799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:01:59+00:00 2026-06-16T17:01:59+00:00

Since Python strives for there to be one right way, I’m wondering what the

  • 0

Since Python strives for there to be one right way, I’m wondering what the purpose of property.getter is. In this example WhyMe defines a getter but Other doesn’t so I’m wondering what the point of property.getter is over just using property.

class WhyMe(object):
    def __init__(self):
        self._val = 44

    @property
    def val(self):
        print 'I am not called'
        return self._val

    @val.getter # What advantage do I bring?
    def val(self):
        print 'getter called'
        return self._val

class Other(object):
    def __init__(self):
        self._val = 44

    @property
    def val(self):
        print 'I AM called'
        return self._val

And using them:

>>> why = WhyMe()
>>> why.val
getter called
44
>>> other = Other()
>>> other.val
I AM called
44

I’m no stranger to properties, I’m just wondering if there is some advantage to making a getter or if was just put there for symmetry?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:02:00+00:00Added an answer on June 16, 2026 at 5:02 pm

    @property let’s you define a whole new property, by defining a getter for that property. The @original.getter syntax lets you override just the existing getter. There are also .setter and .deleter decorators, to the other two methods available to a property.

    Imagine you subclassing a custom class that is using a property, with both a getter and a setter defined. If you only wanted to override the getter of that property but leaving the setter in place (or the deleter), using @BaseClass.original.getter lets you do that:

    >>> class Foo(object):
    ...     @property
    ...     def spam(self):
    ...         print 'Foo.spam called'
    ...         return 'spam'
    ...     @spam.setter
    ...     def spam(self, value):
    ...         print 'Foo.spam.setter called'
    ...     @property
    ...     def ham(self):
    ...         print 'Foo.ham called'
    ...         return 'ham'
    ...     @ham.setter
    ...     def ham(self, value):
    ...         print 'Foo.ham.setter called'
    ... 
    >>> class Bar(Foo):
    ...     @Foo.spam.getter
    ...     def spam(self):
    ...         print 'Bar.spam override'
    ...         return 'eggs and spam'
    ...     @property
    ...     def ham(self):
    ...         print 'Bar.ham override'
    ...         return 'eggs and ham'
    ... 
    >>> Bar().spam
    Bar.spam override
    'eggs and spam'
    >>> Bar().spam = 'foo'
    Foo.spam.setter called
    >>> Bar().ham
    Bar.ham override
    'eggs and ham'
    >>> Bar().ham = 'foo'
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: can't set attribute
    

    Note that I only replaced the spam getter, while it’s setter was preserved. The Bar.ham setter does not exist, I replaced the Foo.ham property wholesale.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since python has way to do nearly everything I was wondering is there any
I setup PyDev with this path for the python interpreter /System/Library/Frameworks/Python.framework/Versions/2.5/Python since the one
I'm using Python since some times and I am discovering the pythonic way to
Since a few weeks I am learning Python and Django. Up to this point
Since there is a python 3.x, why don't we use it? Why do we
Since Python's string can't be changed, I was wondering how to concatenate a string
Since Python does not provide left/right versions of its comparison operators, how does it
Very simple question: Specifically in Python (since Python actually has strongly recommended style guidelines
Since functions are values in Python, how do I determine if the variable is
I want a Python object that will monitor whether other objects have changed since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.