forked from fufvocdi/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.py
More file actions
20 lines (19 loc) · 845 Bytes
/
compile.py
File metadata and controls
20 lines (19 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"compile.py - 用于编译python文件的脚本"
import sys,os,shutil
currdir = os.path.split(__file__)[0]
if len(sys.argv) > 1:
import py_compile
for filename in sys.argv[1:]:
if os.path.isfile(filename):
pycfile = py_compile.compile(filename)#,optimize=2)
print('已编译文件 ' + filename)
if os.path.isfile(pycfile):
shutil.copy(pycfile, os.path.splitext(filename)[0]+".pyc" )
print('复制 {} 到 {}'.format(pycfile,
os.path.splitext(filename)[0]+".pyc"))
else:
print("欢迎使用",__doc__,end='\n\n')
result = input('是否编译当前目录 (%s) 下的所有文件?' % currdir)
if result.lower().startswith('y'):
import compileall
compileall.compile_dir(currdir, maxlevels=50) # optimize=1