Skip to content

Instantly share code, notes, and snippets.

@xoriole
Last active January 2, 2020 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoriole/f40e35cc02fdd11df7b6b830f9ca3a35 to your computer and use it in GitHub Desktop.
Save xoriole/f40e35cc02fdd11df7b6b830f9ca3a35 to your computer and use it in GitHub Desktop.
Print extractor updated to Python3. Based on https://gist.github.com/devos50/31ee8ac2e1758ccccbd74d2a8c5985c5
import ast
import os
import sys
location = os.path.abspath(sys.argv[1])
exclude_from_check = ['twisted/plugins/tunnel_helper_plugin.py']
for (dirpath, dirnames, filenames) in os.walk(location):
for filename in filenames:
if not filename.endswith('.py'):
continue
file_contents = ''
file_path = os.path.join(dirpath, filename)
if any([file_path.endswith(excluded_path) for excluded_path in exclude_from_check]):
continue
with open(file_path, 'r') as file:
file_contents = file.read()
if file_contents:
node = ast.parse(file_contents)
for subnode in ast.walk(node):
if isinstance(subnode, ast.Call) and hasattr(subnode.func, 'id') and subnode.func.id == "print":
print(f"print at line {subnode.lineno}, col {subnode.col_offset} in file {file_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment