Skip to content

Instantly share code, notes, and snippets.

@simplylizz
Created November 26, 2012 20:19
Show Gist options
  • Select an option

  • Save simplylizz/4150361 to your computer and use it in GitHub Desktop.

Select an option

Save simplylizz/4150361 to your computer and use it in GitHub Desktop.
String finder for python code.
"""Parses files in the current dir to find all strings"""
import fnmatch
import os
import ast
class ShowStrings(ast.NodeVisitor):
def visit_Str(self, node):
print node.lineno, node.col_offset, repr(node.s)
if __name__ == '__main__':
for root, dirs, files in os.walk('.'):
for filename in fnmatch.filter(files, '*.py'):
full_name = os.path.join(root, filename)
if ('/migrations/' not in full_name and
'/pycontrol/' not in full_name):
print '### PROCESSING FILE %s ###' % full_name
ShowStrings().visit(ast.parse(open(full_name, 'r').read()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment