Skip to content

Instantly share code, notes, and snippets.

@shindig7
Created June 6, 2020 15:17
Show Gist options
  • Save shindig7/6d57a52068ea096adee11bd85439c866 to your computer and use it in GitHub Desktop.
Save shindig7/6d57a52068ea096adee11bd85439c866 to your computer and use it in GitHub Desktop.
Finds all Python files in a directory and prints the filename if it contains the search string
from pathlib import Path
def search(term):
pys = Path(".").rglob("*.py")
for fp in pys:
with open(fp, "r") as F:
if term in F.read():
print(str(fp).split("\\")[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment