2013년 7월 22일 월요일

파이선 컴파일 py


다운로드 : 다운로드

pyc2py를 응용해서 만듬

사용법도 같당.  python pyccreate.py 컴파일할 파일.py

# Made by yhpdoit
# http://yhpdoit-textcube.blogspot.kr/

import py_compile
import marshal, struct, os, sys, glob, time



def convert(pyfilename):

    pycfilename = pyfilename[:-3] + ".pyc"
    print pycfilename
   
    if pyfilename[-2:] not in ('py'):
        raise TypeError('\nERROR : %r is not a py file' % pyfilename)

    if os.path.exists(pycfilename):
        raise TypeError('\nERROR : %r already exists' % pycfilename)

    py_compile.compile(pyfilename)
    return


def globargs(args=None):

    if args is None:
        args = sys.argv[1:]
    l = []
    for arg in args:
        if glob.has_magic(arg):
            # Glob pattern
            l.extend(glob.glob(arg))
        else:
            # Regular filename
            l.append(arg)
    return l

           
if __name__ == '__main__':
    for pyfilename in globargs():
        print '%s compile to' % pyfilename,
        try:
            pycfilename = convert(pyfilename)
        except (ValueError, TypeError), reason:
            print reason
        else:
            print pycfilename

댓글 없음:

댓글 쓰기