How to define the function class correctly , It is mainly divided into the following situations ：
1. Under the same folder
For... In the same folder py The file is , In theory , In fact, it can be directly normal import The use of , In this case ,dissim_get.py file and lightfm_reco.py file , Want to be in lightfm_reco.py Reference in file dissim_get.py , In fact, you can refer to it directly through the following methods ：
import dissim_get # perhaps from dissim_get import *
If not , It can only dissim_get.py The path of the folder where the file is located is imported to python In the search path of , Just put the folder here lightfm_init Import the path of .
import sys sys.path.append('py The parent directory is located in ')
2. Not in the same folder
Not in the same folder can be divided into the following two cases ：
In both cases , The approach adopted is consistent ：
sys.path.append(' The corresponding path ')
But sometimes it doesn't work , here , It may be because it's building python There is no module __init__.py file , This is because it's building python - module Follow the normal folder directly directory To set up , There is no choice python package , At this time, there is no under the corresponding folder __init__.py file .
There is also a case where citation is not successful , Even with __init__.py The file still can't be quoted successfully , At this point, it's in the quoted python Under bag __init__.py In the file, the function class to be referenced is described by statement ：
__all__=[' Function class name ‘]
Actually , I'm still confused about a situation , Why? git Down in other people's code , You don't need to load the directory to run the code , This situation needs to be studied in detail