On 20/01/15 12:04, jarod...@libero.it wrote:
Dear all, I continue to try to understand some code:
class Tutto():
def __init__(self):
print "Ok"
#@property
def readsets(self,nome):
self.nome = nome
self._readsets = parse_tutto_readset_file(self.nome)
return self._readsets
Why If uncomment the decorator the code not work:
My understanding of the @property decorator is that it is only for
defining read-only properties. In other wordss it expects you to use it
like:
t = Tutto()
myvar = t.readsets
notice no parens and no parameters.
If you want to read the data from a file I'd suggest making the file
part of the constructor and then use readsets as shown above:
class Tutto:
def __init__(self, filename):
self.filename = filename
print 'ok'
@property
def readsets(self):
self._readsets = parse_tutto_readset_file(self.nome)
return self._readsets
p = Tutto("/home/mauro/Desktop/readset.csv")
var = p.readsets
I'd also question why you seem to have a function that has the class
name in its name? Should that function not be a method of the class?
Or is it part of some third party library perhaps?
hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor