創建標準化工程目錄腳本
阿新 • • 發佈:2018-05-26
append sys \n sys.argv code import from imp _file__
# 創建工程目錄腳本
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‘]
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 + ‘\n\n‘)
f.write(‘> Author:‘ + __author__ + ‘\n‘)
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()
創建標準化工程目錄腳本