For some reason, many Python programmers combine a class and its implementation into the same file; I like to separate them, if absolutely necessary.
It's simple. Just create an implementation file, import the module in which this class is defined, and you can call it directly.
So, if the ShowMeTheMoney class is defined inside class1_file.py , and the file structure is:
/project /classes /__init__.py /class1_file.py /class2_file.py /class1_imp_.py
(BTW, the file and class names must be different: the program will fail if the class and file names are the same.)
You can implement it in class1_imp_.py using:
# class1_imp_.py import classes.class1_file as any_name class1_obj = any_name.ShowMeTheMoney()
# class1_imp_.py import classes.class1_file as any_name class1_obj = any_name.ShowMeTheMoney()
Hope this helps.
source share