Test:
Create a new directory: ATM , three new package conf / bin / module in the directory. and create a new . py file bin.py in package conf . Create a new two file in module logger.py / main.py .
1 def logging (): 2 Print ('logging ..... ') ')
logger.py
1 from Import Logger 2 3 def Main (): 4 logger.logging ()56# main ()
main.py
1 from Import Main 2 3 Main.main ()
bin.py
where bin.py as the entry interface of the program
Run up, there seems to be no problem.
" D:\Program Files (x86) \python36\python.exe " f:/atm/bin/bin.pylogging ... and so on. Process finished with exit code 0
Run Results
But one of the errors is hidden:
Here's a demo: Look at the runtime lookup directory of the Python interpreter .....
Compare
How to resolve:
1 ImportSYS2 ImportOS3Base_dir=os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)))4 sys.path.append (Base_dir)5 #sys.path.append (' F:\\atm ')6 fromModuleImportMain7 8 fromConfImportsetting9 Ten Main.main () One A #Print (Os.path.abspath (__file__)) # Get the absolute path F:\ATM\bin\bin.py - # - #Print (Os.path.dirname (__file__)) #拿到绝对路径的目录F:/atm/bin the #Print (Os.path.dirname (Os.path.abspath (__file__))) #F: \atm\bin - #Print (Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) #F: \atm - #Base_dir=os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) - #sys.path.append (Base_dir) + - #print (__file__) # Get relative path bin.py + # A # at #print (Sys.path)
Python Entry 19th Day package