http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/205183 idiom

G

Gabriel Rossetti

Hello,

I am reading core python python programming and it talks about using the
idiom
described on
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/205183 .

I'm using python 2.5.1 and if I try :

class MyClass(object):
def __init__(self):
self._foo = "foo"
self._bar = "bar"

@property
def foo():
doc = "property foo's doc string"
def fget(self):
return self._foo
def fset(self, value):
self._foo = value
def fdel(self):
del self._foo
return locals() # credit: David Niergarth

@property
def bar():
doc = "bar is readonly"
def fget(self):
return self._bar
return locals()

like suggested in the book (the decorator usage) I get this :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() takes no arguments (1 given)

but if I write it just like on the web page (without the decorator, using "x = property(**x())" instead) it works :
'foo'

does anyone have an idea as of why this is happening?

Thanks,
Gabriel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top