Python Entry 19th Day package

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.