There is , which loads ( from ploader import * ) python script . Other classes are loaded in . So, the question is actually how to expand the already declared classes in scripts (which loads).

For example, the CommonThread class is declared in CommonThread , which will be necessary in all scripts in the future, since they must extend it. Is this even possible?

Tried by:

 class MyThread(CommonThread) ... 

He says that there is no such class ( CommonThread ) and nothing to inherit.

  • I didn’t quite understand: in which modules you need to expand - in importing or imported into it? - skegg pm
  • 2
    I think you should throw the code on and bring it here, but that is not very clear. - rnd_d
  • I guess I explained a lot of things confusingly. It turns out that there is init .py, it will start the program and import (the loader of the necessary modules) into itself. There is a CommonThread class - which defines subsequent module classes that should inherit it. But, since I declare it in, and only then I import subsequent classes-modules - the problem appears, writes that there is no such class: class MyThread (CommonThread) --- NameError: name 'CommonThread' is not defined - kulikov. im
  • @ akm74, just give a piece of code where your problem is reproduced. - Ilya Pirogov
  • one
    and what do the three points mean? and then my head was spinning - rnd_d

1 answer 1

In my opinion, you have some kind of misunderstanding of how Python modules work. And this is path.append(getcwd()+"/plugins") - in general there is some kind of heresy.

I think you need to read PEP 328 and PEP 8 at the same time.

If I understand everything correctly, then this is something similar to php. That is, the class is declared in one file, for example, in the file - class.php , and is inherited in the extend_class.php file. With this format, if I do include("class.php"); in the index.php file include("class.php"); and then include("extend_class.php"); - then we can safely inherit the class. How can this be implemented in Python? :

 class FooClass: pass :

 import foo class BarClass(foo.FooClass): pass :

 import foo, extend_foo obj1 = foo.FooClass() obj2 = extend_foo.BarClass() 
  • thank you .. as for - path.append (getcwd () + "/ plugins") if you know how you can import directly from a folder without adding this folder - tell me how. The project structure is as follows: ./ ./ (initializing the program and launching the Loader from the ./plugins/ file) ./plugins/ (directory of reference classes for inheritance + plugins) (plug-in initializer) ) -
  • one
    > if you know how you can import directly from a folder without adding this folder - tell me how. The first link in the message. - Ilya Pirogov
  • Thank you, you really helped! -