Skip to content

Instantly share code, notes, and snippets.

@nickpascucci
Created October 6, 2011 16:57
Show Gist options
  • Save nickpascucci/1267938 to your computer and use it in GitHub Desktop.
Save nickpascucci/1267938 to your computer and use it in GitHub Desktop.
Function to parse TODO comments from python source files.
# TODO parser part 2
def get_todos(files):
"""Create a list of TODO information based on the given files.
@param files: List of paths to Python source files.
@return: List of (person, date, file, line, text) tuples corresponding to
TODO comments in the given sources.
"""
comments = []
for source_filename in files:
source_file = open(source_filename, "r")
line_number = 0
for line in source_file:
line_number += 1
line = line.strip()
if line.startswith("# TODO"):
elements = line.split(":")
todo_info = (elements[2],
elements[1],
source_filename,
str(line_number),
elements[3].strip())
comments.append(todo_info)
return comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment