python软件开发规范
代码目录结构如下:
software:
--bin
--conf
--core
--db
--lib
--log
截图如下:
主要程序文件在core.py文件中,但是调用是通过start.py调用的,
start.py文件内容如下:
import os import sys Base_path = os.path.dirname(os.path.dirname(__file__)) sys.path.append(Base_path) from core import main if __name__ == '__main__': main.entry_point()
main.py需要调用auth.py,示例代码如下:
from core import auth def entry_point(): print("这是程序的入口") auth.login()
auth.py需要读取配置文件,示例代码如下:
from conf import settings def login(): # name = "leon" print("这个是登录函数,登录的用户名是%s"%settings.name) print("打开了",settings.file_path) print("打开了",settings.user_path)
配置文件中可以对文件目录做个整理,如下:
import os name = "gary" bath_path = "D:\python\学习\基础\day31" file_path = os.path.join(bath_path,"soft","db","leon.json") user_path = os.path.join(bath_path,"soft","db","gary.json")