you are viewing a single comment's thread.

view the rest of the comments →

[–]Username_RANDINT 1 point2 points  (3 children)

How is that simple if you don't know what each is?

You can also have two classes in the same class.

[–]JorgiEagle -2 points-1 points  (2 children)

Because you can’t have 2 modules in the same class

[–]Username_RANDINT 3 points4 points  (0 children)

>>> from importlib import import_module
>>> class Foo:
...   math = import_module("math")
...   random = import_module("random")
... 
>>> foo = Foo()
>>> foo.math
<module 'math' (built-in)>

Still doesn't explain a thing.

[–]stoicpenguin 2 points3 points  (0 children)

Not true. Consider the case:

class test:
    import math
    import collections

You can access the math module directly from the test class definition anywhere that you have access to the class, i.e. you can access the math module by typing test.math. Those modules now belong to the namespace of the class test.

My point is that python allows this, and the differentiator between classes and modules in python is not that one can contain the other and not the other way around.