I can split a class definition in multiple files only if these are located in the same directory:
# entrypoint.py
class C(object):
from ImplFile import OtherMethod
def __init__(self):
self.a = 1
# ImplFile.py
def OtherMethod(self):
print("a = ", self.a)
If the ImplFile.py
file is in a subdirectory, I get the error:
ModuleNotFoundError: No module named 'OtherMethod'
How can I specify that the member function is defined in that file?
The reason I want to split the implementation in more than one file is due to its size, both in terms of number of member functions and their size.
As mentionned by DeepSpace and Tim Roberts, it's quite bad practice what you're doing mainly because it's difficult to understand what's going on when you're reading your code without any explanations or documentation.
If you really insist on continuing on the same path, simply add the subdirectory's name before the filename in the Import statement:
from <subdirectory>.ImplFile import OtherMethod
If, however, you wish to proceed with a cleaner code, the best option in your case would probably be to use Inheritance.
You can create your Parent Class with the base attributes and methods in you main file and then create Child Classes in other files/subdirectories with additionnal methods/attributes.