How to replace constructor with factory method

2009-05-11 Thread rogeeff
Hi, Just wonder if it's possible in Python. what I want is to tweak an existing Python class A with no constructor, so that A() results in fuctory method call? so o = A() instead being equivalent to: s = object() A.__init__(s) o = s becomes: o = my_factory_function( A ) Thanks, Gennadiy --

Re: How to replace constructor with factory method

2009-05-11 Thread Chris Rebert
On Mon, May 11, 2009 at 1:39 PM, roge...@gmail.com wrote: Hi, Just wonder if it's possible in Python. what I want is to tweak an existing Python class A with no constructor, so that A() results in fuctory method call? so o = A() instead being equivalent to: s = object() A.__init__(s)

Re: How to replace constructor with factory method

2009-05-11 Thread Luis Zarrabeitia
On Monday 11 May 2009 04:39:41 pm roge...@gmail.com wrote: so o = A() instead being equivalent to: s = object() A.__init__(s) o = s Actually, it would be more like this: s = A.__new__(A) if isinstance(s,A): A.__init__(s) o = s o = my_factory_function( A ) You could tweak: *) A's