getFoo1() vs. class.foo1

Manuel manuelbastioniNOSPAM at tin.it
Fri Jun 13 19:29:35 EDT 2003


Hi, I'm python beginner.
My first class is very simple, like

class VerySimple:
        foo1 = 1
        foo2 = 2
        foo3 = 3
etc...

Any professional developers tell me that
I must use get and set (to private variable)
method instead.
Because this mean many many lines added,
I want ask the difference between two methods.

The simple class above begin:

class VerySimple:
        __foo1 = 1
        __foo2 = 2
        __foo3 = 3

       def getFoo1(self):
            return __foo1
       def getFoo2(self):
            return __foo2
       def getFoo3(self):
            return __foo3

       setFoo1(self,val):
            __foo1 = val
       setFoo2(self,val):
            __foo2 = val
       setFoo3(self,val):
            __foo3 = val

I've add a lot of line. It' necessary in all cases?

thx,

             Manuel







More information about the Python-list mailing list