If you wanted to avoid an eval(), you could just do:
id = "1234asdf"
constructor = globals()[id]
instance = constructor()
Provided that the class is defined in (or imported into) your current scope.
More Related Contents:
- Why is __init__() always called after __new__()?
- Meaning of @classmethod and @staticmethod for beginner? [duplicate]
- Is there a simple, elegant way to define singletons? [duplicate]
- How to list all functions in a Python module?
- How to make a class property? [duplicate]
- What is the purpose of class methods?
- How can I get a list of all classes within current module in Python?
- How to list all functions in a module?
- How to dynamically load a Python class
- How to enumerate an object’s properties in Python? [duplicate]
- elegant find sub-list in list
- Attaching a decorator to all functions within a class
- Is there a simple, elegant way to define singletons? [duplicate]
- Python: changing methods and attributes at runtime
- How to check whether a variable is a class or not?
- How to write Strategy Pattern in Python differently than example in Wikipedia?
- Why is __init__() always called after __new__() in Python?
- __getattr__ for static/class variables
- Python: is using “..%(var)s..” % locals() a good practice?
- Why is IoC / DI not common in Python?
- Implementing the decorator pattern in Python
- Convert a python ‘type’ object to a string
- When should I use @classmethod and when def method(self)?
- What’s an example use case for a Python classmethod?
- How to auto register a class when it’s defined
- Using a class’ __new__ method as a Factory: __init__ gets called twice
- Auto-register class methods using decorator
- Same name for classmethod and instancemethod
- Nested Blueprints in Flask?
- What is the best approach in python: multiple OR or IN in if statement?