Created
June 6, 2020 15:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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