Created
November 8, 2013 19:57
-
-
Save sposterkil/7376706 to your computer and use it in GitHub Desktop.
Demo of McCabe complexity moving things into a separate function
This file contains hidden or 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
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