instantiate a 'classobj'
attn.steven.kuo at gmail.com
attn.steven.kuo at gmail.com
Thu Jul 26 22:55:14 EDT 2007
On Jul 26, 7:03 pm, westymatt <westym... at gmail.com> wrote:
> I have a class where a parameter to its constructor is a type(param) =
> 'classobj'. How would I go about instantiating that given it has no
> constructor.
A old style class may not have a __new__ attribute, but it's still
callable, right?
class NewStyle(object):
def __init__(self, old_style_cls):
self.osc_instance = old_style_cls()
self.osc_type = type(old_style_cls)
def introspection(self):
print "Instrospection shows..."
print self
print self.osc_instance
print self.osc_type
class OldStyle: pass
print type(OldStyle)
ns = NewStyle(OldStyle)
ns.introspection()
--
Hope this helps,
Steven
More information about the Python-list
mailing list