all the bytecode files in tree because these are not always portable across major python releasesit' usually good idea to ship programs without them and let python create new ones on first imports now that we're expert os walk userswe could cut out the middleman and use it directly example - codes portable and general commandline toolwith support for argumentsexception processingtracingand list-only mode example - pp \tools\cleanpyc py ""delete all pyc bytecode files in directory treeuse the command line arg as root if givenelse current working dir ""import ossys findonly false rootdir os getcwd(if len(sys argv= else sys argv[ found removed for (thisdirlevelsubsherefilesherein os walk(rootdir)for filename in fileshereif filename endswith(pyc')fullname os path join(thisdirlevelfilenameprint('=>'fullnameif not findonlytryos remove(fullnameremoved + excepttypeinst sys exc_info()[: print('*'* 'failed:'filenametypeinstfound + print('found'found'filesremoved'removedwhen runthis script walks directory tree (the cwd by defaultor else one passed in on the command line)deleting any and all bytecode files along the wayc:\examples\pp etools\cleanpyc py = :\users\mark\stuff\books\ \pp \dev\examples\pp \__init__ pyc = :\users\mark\stuff\books\ \pp \dev\examples\pp \preview\initdata pyc = :\users\mark\stuff\books\ \pp \dev\examples\pp \preview\make_db_file pyc = :\users\mark\stuff\books\ \pp \dev\examples\pp \preview\manager pyc = :\users\mark\stuff\books\ \pp \dev\examples\pp \preview\person pyc more lines here found filesremoved :\pp \toolscleanpyc py =\find pyc =\visitor pyc =\__init__ pyc found filesremoved searching directory trees