Thanks for all replies. I'll just to have to figure our which suggested
method I should use. To answer Jussi's question, this is why I asked
the question. I have the book by Mark: Python Programming on Win32.
In Charpter 12: Advanced Python and COM there is a sample code named:
DynamicPolicy.py.
On Wed, 03 Jan 2007 23:27:57 -0800, wcc wrote:
> Hello,
>
> How do I create a class using a variable as the class name?
Try a "class factory".
def create_class(classname):
class Klass(object):
def __init__(self):
print "Creating object of %s..." % self.__class__.__name__
wcc kirjoitti:
> Hello,
>
> How do I create a class using a variable as the class name?
>
> For example, in the code below, I'd like replace the line
>
> class TestClass(object):
> with something like
> class eval(className) (object):
>
> Is it possible? Thanks for your help.
>
> className =
wcc schrieb:
> Hello,
>
> How do I create a class using a variable as the class name?
>
> For example, in the code below, I'd like replace the line
>
> class TestClass(object):
> with something like
> class eval(className) (object):
>
> Is it possible? Thanks for your help.
>
> className = "T
Or if you have required class name in variable, then use:
class TestClass:
pass
globals()[className] = TestClass
--
Tõnis
On Jan 4, 9:27 am, "wcc" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> How do I create a class using a variable as the class name?
>
> For example, in the code below, I'd like
You can always rename your defined clas afterwards
class TestClass:
pass
myClass = TestClass
--
Tõnis
On Jan 4, 9:27 am, "wcc" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> How do I create a class using a variable as the class name?
>
> For example, in the code below, I'd like replace the line
>
Hello,
How do I create a class using a variable as the class name?
For example, in the code below, I'd like replace the line
class TestClass(object):
with something like
class eval(className) (object):
Is it possible? Thanks for your help.
className = "TestClass"
class TestClass(object):