__author__ = 'wei'
# -*- coding: utf-8 -*-
__author__ = 'wei'
import getopt
import sys
import os
import py_compile
def setparams():
global srcpath,pycpath
ps=getopt.getopt(sys.argv[1:], '', ['srcpath=', 'pycpath='])
psdict=dict(ps[0])
if '--srcpath' in psdict:
srcpath=psdict['--srcpath']
else:
srcpath=input('请输入源文件夹:')
if '--pycpath' in psdict:
pycpath=psdict['--pycpath']
else:
pycpath=input('请输入目标pyc文件夹:')
if __name__=='__main__':
srcpath=''
pycpath=''
setparams()
print(srcpath)
for root,dirs,files in os.walk(srcpath):
for file in files:
if file[-3:]=='.py':
pyname=root+os.path.sep+file
pycname=pyname.replace(srcpath,pycpath)+'c'
pycdir=pycname.replace(file+'c', '')
if not os.path.exists(pycdir): #if not exist dir,create it
os.mkdir(pycdir)
print(pyname,pycname)
py_compile.compile(pyname,cfile=pycname)python将项目文件打包发布的脚本(保留原来的项目结构)
本文介绍了一段Python脚本,用于自动化设置参数并编译Python文件为.pyc文件。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

被折叠的 条评论
为什么被折叠?



