what is the difference between @property and method

Devin Jeanpierre jeanpierreda at gmail.com
Thu Feb 9 10:05:06 CET 2012


On Thu, Feb 9, 2012 at 3:50 AM, Zheng Li <dllizheng at gmail.com> wrote:
> class A(object):
>    @properymethod
>    def value1(self):
>         return 'value1'
>
>    def value2(self):
>        return 'value2'
>
> what is the difference between value1 and value2.

There is no such thing as @properymethod

After you change the code to use @property, try writing it in the
interactive interpreter and calling A().value2(). Then try calling
A().value1() .

Or maybe try googling for it. The fourth result for "property python"
for me is http://adam.gomaa.us/blog/2008/aug/11/the-python-property-builtin/

--

It is kind of funny that the docs don't ever explicitly say what a
property is. http://docs.python.org/library/functions.html#property

-- Devin



More information about the Python-list mailing list