Skip to content
Advertisement

Dynamically created classes with the same name

I’m trying to dynamically create subclasses in Python with type:

JavaScript

and here’s what I see in the output:

JavaScript

Obviously, this was not my intention. Two questions in that respect:

  1. How does Python handles multiple classes with identical names?
  2. What is a pythonic way to handle it? Of course, I can look up the name in the already existing subclasses, but then how to deal with namespaces/modules?

Advertisement

Answer

Python doesn’t care overmuch about the classname, these will be different classes, you just need to have a mechanism to save and look up the classes you want.

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement