First of all, it looks like you can reinvent the wheel a bit ... most Python web frameworks (CherryPy / TurboGears is what I know) already include a way to send requests to specific classes based on URL content or user input.
There is nothing wrong with the way you do this, but, in my experience, it tends to indicate some kind of โmissing abstractionโ in your program. You mostly rely on the Python interpreter to store a list of objects that you might need, and not to store it.
So, as a first step, you might just need to make a dictionary of all the classes you want to call:
dispatch = {'Foo': Foo, 'Bar': Bar, 'Bizbaz': Bizbaz}
Initially, this will not make much difference. But as your web application grows, you can find several advantages: (a) you will not encounter namespace conflicts, (b) using globals() , security issues can arise where an attacker can essentially gain access to any a global character in your program, if they can find a way to insert an arbitrary classname into your program, (c) if you ever want to have a classname as something other than a real exact class name, using your own dictionary will be more flexible (d) you can deputy it Dictionary dispatch more flexible user class that has access to a database or something like that, if you find it.
Security issues are especially important for a web application. Doing globals()[variable] , where variable is entered from a web form, just asks for problems .
Dan lenski
source share