John wrote:
> Hi, is it possible to instantiate a class with a variable.
> 
> example
> 
> class foo:
>     def method(self):
>         pass
> 
> x='foo'
> 
> Can I use variable x value to create an instance of my class?

You got examples using string 'foo', now if all you need is to store or
pass around the class, just use it as any other object (yes, classes
*are* objects):

class Foo(object): pass

x = Foo

f = x()
assert type(f) is Foo


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to