[Tutor] Properties of an object
kent37 at tds.net
Fri Jan 30 12:43:16 CET 2009
On Thu, Jan 29, 2009 at 1:59 PM, Vicent <vginer at gmail.com> wrote:
> This is an easy question, I guess, but I am not able to find out the answer.
> In fact, it is both a Python question and a general programming "style"
> I want to define a class that contains a list (or a NumPy array) of elements
> of a certain type, and an integer:
> class ExampleList :
> def __init__(self, list, position) :
> self.list = list
> self.position = position
> This is clear to me.
> My first question, which is Python related:
> (1) Where are the right places to define PROPERTIES for my class, and how (I
> mean, which is the right syntax) must I define them?
A note on terminology: In Python, what you are describing is called an
attribute. 'property' has a very specific meaning, it is a way to
associate a value with an instance that uses attribute notation for
access, i.e. a.b, but actually uses a method call to get and set the
value. In other words, it provides the flexibility of getters and
setters with the notation of a plain attribute. Moreover, you can
change a value from an attribute to a property without changing client
code at all. This might be appropriate for your 1stpart and 2ndpart
More information about the Tutor