Python project structure specifications and calls between files

Source: Internet
Author: User

Structural uses of the specification:

1. High readability

2. High maintainability

Brief introduction of the document:

1.bin/: Store Some executable files of the project, of course you can name acript/or something.

2.foo/: Store The source code of the project:

(1) All modules in the source code, the package should be placed in this layer directory

(2) Its sub-directory tests/Store unit test code

(3) The entrance of the program should be named main.py

3.docs/: Storing some documents

4.setup.py: Installation, deployment, packaged scripts

5.requirements.txt: List of external Python treasures since the software was stored

6.README: Description file for Project

1. Locate the current file path

Relative path: The terminal can view the path of the required file,

Print (__file__)

PWD, the output function results in a relative path.

2. Import the library file and find the parent file path

3. Functions that call the main file

ImportOSImportSYS#how to find the offspring of the Fathers#How to get the path to the current filePrint('-----Relative Path-----')#relative path: Execute command under terminal, enter file Python atm.pyPrint(__file__)Print('-----Absolute Path: The OS library needs to be imported-----')#If you want the absolute path of the current file, import the library OSPrint(Os.path.abspath (__file__))Print('-----father-level directory-----')#top-level path on current filePrint(Os.path.dirname (Os.path.abspath (__file__)))Print('-----Grandfather Category-----')#Grandfather Level CataloguePrint(Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))))#Grandpa Level directory pathBase_dir = Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)) ) sys.path.append (base_dir)#Import Configure,core#Import the required file name from the uncle's level directory fromConfigureImportsetting fromCoreImportMain#file Fetch functionMain.login ()
View Code
def login ():     Print ('Welcome to my mainfunction') Print ('Check---')
View Code

Python project structure specifications and calls between files

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.