Not sure how to phrase this question

Arthur ajs at ix.netcom.com
Mon Sep 16 18:55:28 EDT 2002


Hoping I can get some help digesting the following
behavior.
************************************
class returnClassic(object):
    def __new__(self):
        return Classic()
class callClassic(object):
    def __new__(self):
       Classic()
class returnNewStyle(object):
    def __new__(self):
        return NewStyle()
class callNewStyle(object):
    def __new__(self):
       NewStyle()
class returnNewStyle(object):
    def __new__(self):
       return NewStyle()

class Classic:
    def __init__(self):
        print "Classic class init"
class NewStyle(object):
    def __init__(self):
        print "NewStyle class init"


if __name__ == "__main__":
   print "call to callClassic()" 
   cc=callClassic()
   print cc.__class__
   print "*************" 
   print "call to returnClassic()" 
   rc=returnClassic()
   print rc.__class__
   print "*************" 
   print "call to callNewStyle()" 
   cns=callNewStyle()
   print cns.__class__
   print "*************" 
   print "call to returnNewStyle()" 
   rns=returnNewStyle()
   print rns.__class__
   
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> 
call to callClassic()
Classic class init
<type 'NoneType'>
*************
call to returnClassic()
Classic class init
__main__.Classic
*************
call to callNewStyle()
NewStyle class init
<type 'NoneType'>
*************
call to returnNewStyle()
NewStyle class init
NewStyle class init
<class '__main__.NewStyle'

***********************************************8
Problem being for what I am after the "returnClassic" seems
to be the simplest alternative.  But would  I be relying on what is
essentially a side-effect.

The "returnNewStyle" seems to actually create 2 instances, while
the "callNewStyle" seems to create a class in some netherworld
between existence and non-existence.

Would hate to have to resort to truely understanding
this stuff to get to where I am hoping to get. 


Art






More information about the Python-list mailing list