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:
main.py283 chars11 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