Skip to content

Instantly share code, notes, and snippets.

@sposterkil
Created November 8, 2013 19:57
Show Gist options
  • Save sposterkil/7376706 to your computer and use it in GitHub Desktop.
Save sposterkil/7376706 to your computer and use it in GitHub Desktop.
Demo of McCabe complexity moving things into a separate function
def prepare_line_list(line):
line_list = re.split("\s+", line)
# Use of re.split adds an empty element to the list
del line_list[len(line_list) - 1]
# Add empty field if we don't have a middle name
if len(line_list) is not 7:
line_list.insert(3, "")
# Remove "F13" if it's there, complain otherwise
if line_list[5] == "F13":
del line_list[5]
else:
bad_input('Fifth Field is not "F13". Bad file?')
return line_list
def main():
for line in fileinput.input():
line_list = prepare_line(line)
for word in line_list[1:3]:
word = word.capitalize()
print "final line"
print line_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment