[BangPypers] missing something

Senthil Kumaran orsenthil at gmail.com
Tue Jun 22 05:35:49 CEST 2010


On Sat, Jun 19, 2010 at 8:56 PM, Zubin Mithra <zubin.mithra at gmail.com> wrote:
> Hi everyone,
>
> I think I`m missing something very basic or have a very basic concept
> understood the wrong way, so I`d like to have some help here.

Before, the real important thing, it would help to analyze these:

What will happen in this snippet:

class C:
    def a(self, a):
        print a
    def a(self, a, b=None):
        print a, b

obj = C()
obj.a(10)
obj.a(10,20)

And in this snippet:

class C:
    def a(self, a, b=None):
        print a, b
    def a(self, a):
        print a

obj = C()
obj.a(10)
obj.a(10,20)

You will see that second one fails and the last method in the
definition is taken as the signature all the times. ( I am trying to
find a reference explanation, but i can't get), which also leads to
The real important thing. :)

These are not a good ways of doing in Python. In Python, all member
functions are effectively 'virtual'. The last I saw these kind of
methods were when studying C++ about virtual methods.

You might just want to define a single method with the variable
parameters set to a default, if you want to have any flexibility in
invocation.

-- 
Senthil


More information about the BangPypers mailing list