constructor overloading like Java ?

Markus Jais mjais at web.de
Mon May 26 06:58:04 EDT 2003


hello

can something like this be done in Python ?

_______________________________________________
class MyObject
{
          public MyObject()
          {
                 System.out.println("uno");
          }
}

class MyClass
{
          private int a;
          private MyObject my;

          public MyClass(int a)
          {
                 this.a = a;
          }

          public MyClass(MyObject my)
          {
                 this.my = my;
          }
          
}


class MyTest
{

          public static void main(String args[])
          {

                 MyClass mc1 = new MyClass(42);
                 MyClass mc2 = new MyClass(new MyObject());
          }
}
__________________________________________

I want several constructors who expect different types
of arguments.
maybe I could use default Arguments but this is not possible if 
I want a lot of more constructors with different parameters.

how could I do something similar in Python ??

Markus











More information about the Python-list mailing list