отчистка файлов *.pyc в windows in python

You can use the os module in Python to delete all files with the .pyc extension in a directory. Here's an example code snippet that deletes all .pyc files in the current working directory:

import os

# get current working directory
dir_path = os.getcwd()

# loop through all files in the directory
for filename in os.listdir(dir_path):
    # if the file has a .pyc extension, delete it
    if filename.endswith('.pyc'):
        os.remove(os.path.join(dir_path, filename))
283 chars
11 lines

This code first gets the current working directory using the getcwd() function from the os module. It then uses a for loop to iterate through all files in the directory using the listdir() function. For each file in the directory, the code checks if the file has a .pyc extension using the endswith() method. If the file has a .pyc extension, it is deleted from the directory using the remove() method from the os module.

Note that this code will permanently delete all .pyc files in the directory, so use it with caution. If you need to delete .pyc files in a specific directory, replace os.getcwd() with the path to that directory.

gistlibby LogSnag