import file2
loads the file2 module and associates it with the file2 name in the current namespace. b from file2 is available as file2.b , not b , so it is not recognized as a method. You can fix it with
from file2 import b
which will load the module and assign function b from this module to the name b . I would not recommend it. Import file2 at the top level and define a method that delegates file2.b , or define a superclass that you can inherit if you often need to use the same methods in unrelated classes. Importing a function to use it as a method is confusing, and it breaks if the function you are trying to use is implemented in C.
source share