创建标准化工程目录脚本

# 创建工程目录脚本

import os
import sys

__author__ = 'LH'
path = os.path.dirname(os.path.abspath(__file__))


def start_project():
    '从命令行建立新的工程名,默认是lh'
    project_name = 'lh_demo'
    if len(sys.argv) > 1:
        project_name = sys.argv[1]

    # 创建标准化目录 与 __init__文件
    folders = ['bin', 'conf', 'core', 'db', 'log', 'utils']
    for folder in folders:
        folder_path = os.path.join(path, project_name, folder)
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)

        with open(os.path.join(path, project_name, folder, '__init__.py'), 'w'):
            pass

    # 创建readme
    with open(os.path.join(path, project_name, 'readme.md'), 'w') as f:
        f.write('#'+project_name + '

')
        f.write('> Author:' + __author__ + '
')


def main():
    start_project()

if __name__ == '__main__':
    main()

使用方法: 在命令行终端 输入 python startproject.py 工程名

程序的入口bin-》main.py中需要定义当前的环境

import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)


from core import memo


def main():
    m = memo.Memo()
    m.test()

if __name__ == '__main__':
    main()
原文地址:https://www.cnblogs.com/louhui/p/9092687.html