Python Road -15-Software Catalog Structure specification

Source: Internet
Author: User

15.1 hierarchy of Clear directory structure

1. High readability : people who are unfamiliar with the code of this project can read the directory structure at a glance, know which program startup script is, where the test directory is, where the configuration file is, and so on. To get to know this project very quickly.

2. High maintainability : Once you have defined your organization's rules, the maintainer will be able to know exactly what directory the new file and code should be placed in. The benefit is that as time goes on, the size of the code / configuration increases and the project structure is not cluttered and can still be well organized.

15.2 Directory organization method

Assuming that your project is named Foo, I would recommend the most convenient and quick directory structure that would suffice :

foo/

|--bin/

| |--Foo

|

|--foo/

| |--tests/

|   | |--__init__.py

|   | |--test_main.py

| |

| |--__init__.py

| |--main.py

|

|--docs/

| |--conf.py

| |--Abc.rst

|

|--setup.py

|--Requirements.txt

|--README

briefly explain :

Bin/: To store some executable files of the project, of course you can name script/and so on.

foo/: Stores all source code for the project. (1) All modules and packages in the source code should be placed in this directory. Do not place the top level directory. (2) Its subdirectory tests/storage unit test code; (3) The entrance of the program is preferably named main.py.

Docs/: Store some documents.

setup.py: Scripts to install, deploy, and package. Setuptools Management

Requirements.txt: A list of external Python packages that store software dependencies.

README: project documentation.

Note: Open source projects may need to increase License.txt,changelog.txt files, etc.

about the Readme content (one file should be available for each project)

it needs to illustrate several things :

Software positioning, the basic functions of the software.

How to run your code : Installation Environment, startup commands, and so on.

Brief instructions for use.

Code directory structure Description, more detailed can explain the basic principles of the software.

FAQ's description.

15.3 calls between different modules

    1. Relative path and absolute path

#print (__file__) # # #在pycharm上执行的是绝对路径, but the program is executed in the background, printing a relative path

#print (Os.path.abspath (__file__)) # # #动态获得绝对路径
#print (Os.path.dirname (Os.path.abspath (__file__)) # # #找上级父目录
#print (Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) # # #找上上级父目录

    1. Calls between modules

New CatalogAtmin theAtmunder NewPython Packagerespectively isbin,conf,Core,New Cataloglogs. Binunder Newpython filename isatm.py,confNewpython fileto beSetting.py,coreunder Newpython filenamemain.py

now call the core under the atm.py file via the bin main.py The function in the file.

atm.py

Import OS
Import sys

Base_dir = Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)))
Sys.path.append (Base_dir)
from conf import setting
from core import Main
Main.login ()

main.py

#! Author:lanhan
def Login ():
Print ("Welcome to my ATM")

Python Road -15-Software Catalog Structure specification

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.