File m1.py :

 x = 1 def y(): return 2 # ... Много переменных и функций ... 

How to make the class Foo contain everything that contains the module m1 ?

I tried this:

File m2.py :

 import m1 class Foo(m1): pass 

But got an error:

 TypeError: module.__init__() takes at most 2 arguments (3 given) 
  • If not a secret for what is it necessary? - Avernial
  • @Avernial, there is a very large class. I decided to break it into modules without classes, so that it would be easier to navigate the code. - pank
  • Isn't it easier then to work directly with modules or break a large class into several smaller ones? - Avernial
  • @Avernial, I agree. It will be easier. - pank

2 answers 2

To make everything from the module available in your class, you can update the dictionary of the object itself.

 import math class Foo(object): def __init__(self): self.__dict__.update(math.__dict__) f = Foo() print(dir(f)) print(f.sqrt(10)) 

The variant proposed by Alexander will also work, but in this variant you will not see the contents until you explicitly refer to the required function or variable.

    Try this:

     import m1 class Foo(object): def __getattr__(self, item): return m1.__dict__[item]