import os for testpackage in ('..\\testres','..\\testwx'): for file in os.listdir( testpackage ): if ( os.path.splitext( file )[1].lower() == '.py' and file != '__init__.py' ): f = os.path.join( testpackage, file ) print 'del', f os.remove( f )