Initialise class object by name

python

Solution

If the class is in your scope:

get_class = lambda x: globals()[x]

If you need to get a class from a module, you can use `getattr`:

import urllib2
handlerClass = getattr(urllib2, 'HTTPHandler')

Problem

Since everything in python is an object, i was wondering if there was a way i could initialise a class object using the name of the class for example, ``` class Foo: """Class Foo""" ``` How could i access this class by "Foo", ie something like `c = get_class("Foo")`

Original source

Related problems