selecting a class in execution time
Raseliarison nirinA
nirina at mail.blueline.mg
Tue Apr 8 16:54:10 EDT 2003
Maybe you want something like this:
>>> class TheClass:
def Name(self):
print 'a name from a class'
>>> TheClass
<class __main__.TheClass at 0x00AD7270>
>>> object = TheClass()
>>> object
<__main__.TheClass instance at 0x00AE35F8>
>>> object.Name
<bound method TheClass.Name of <__main__.TheClass instance at 0x00AE35F8>>
>>> object.Name()
a name from a class
If this is saved as 'MyPackage.py', you can select TheClass with:
>>> from MyPackage import TheClass
or create the object like
>>> import MyPackage
>>> object = MyPackage.TheClass()
>>> object
<MyPackage.TheClass instance at 0x00AF7378>
>>> object.Name
<bound method TheClass.Name of <MyPackage.TheClass instance at 0x00AF7378>>
>>> object.Name()
a name from a class
HTH
nirinA
----- Original Message -----
From: <cybersamurai at mac.com>
To: <python-list at python.org>
Sent: Monday, April 07, 2003 9:09 PM
Subject: selecting a class in execution time
> have some way to do this on Python?
>
> Object x = Class.forName( "mypackage.TheClass" ).newInstace();
> (this is a java code)
More information about the Python-list
mailing list