ImportOSImportSYS fromPy_compileImportCompile#print "Argvs:", sys.argvifLen (sys.argv) = = 3: comd= Sys.argv[1] Path= Sys.argv[2] ifOs.path.exists (PATH) andOs.path.isdir (path): forParent,dirname,filenameinchOs.walk (path): forCFileinchFilename:fullname=Os.path.join (parent,cfile)ifCOMD = =' Clean' andCfile[-4:] = ='. PYc': Try: Os.remove (FullName)Print "Success Remove file:%s"%FullNameexcept: Print "Can ' t remove file:%s"%FullNameifCOMD = ='Compile' andCfile[-3:] = ='. PY': Try: Compile (FullName)Print "Success Compile file:%s"%FullNameexcept: Print "Can ' t compile file:%s"%FullNameifCOMD = ='Remove' andCfile[-3:] = ='. PY' andCFile! ='settings.py': Try: Os.remove (FullName)Print "Success Remove file:%s"%FullNameexcept: Print "Can ' t remove file:%s"%FullNameElse: Print "Not a directory or direcotry doesn ' t exist!"Else: Print "Usage:" Print "\tpython compile_pyc.py Clean path\t\t#to-all PYC files" Print "\tpython compile_pyc.py compile path\t\t#to generate PYC files" Print "\tpython compile_pyc.py Remove path\t\t#to remove py files"
Python releases version PYc script