Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > idiom

Thread Tools idiom

Gabriel Rossetti
Posts: n/a

I am reading core python python programming and it talks about using the
described on .

I'm using python 2.5.1 and if I try :

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

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

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 :

>>> a=MyClass()

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 :

>>> a = MyClass()


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


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which exception idiom do you prefer? Java 6 02-28-2006 06:39 PM
Simplified DOM idiom for building XML - revisited Steve Jorgensen XML 4 08-28-2005 08:54 PM
Idiom Question - Finding Instances Rhino Java 5 02-18-2004 05:36 AM
Pimpl Idiom Icosahedron C++ 7 11-22-2003 11:34 PM
Re: Extendable envelope/letter idiom Ivan Vecerina C++ 0 06-24-2003 01:32 PM