Permalink
Browse files

Main action moved to main() function to allow for file imports

  • Loading branch information...
1 parent 33fcea6 commit 0dc36cc26e8f86a694cb33c0972c310ca9d2a85e @ChimeraCoder committed Apr 25, 2012
Showing with 19 additions and 15 deletions.
  1. +19 −15 instavote/instant_runoff_calculator.py
@@ -2,22 +2,26 @@
import BallotParser
import sys
-ballot_created = False
+def main(infile):
+ ballot_created = False
-while not ballot_created:
- try:
- ballots_file = sys.argv[1]
- ballot_box = BallotParser.BallotBox(ballots_file)
- ballot_created = True
- except (IndexError, IOError):
- print('Please enter the relative path to the file')
- sys.argv = [None, raw_input(),]
+ while not ballot_created:
+ try:
+ ballots_file = infile
+ ballot_box = BallotParser.BallotBox(ballots_file)
+ ballot_created = True
+ except (IndexError, IOError):
+ print('Please enter the relative path to the file')
+ sys.argv = [None, raw_input(),]
-for ballot in ballot_box.ballots:
- print(ballot.candidates)
-
-
+ for ballot in ballot_box.ballots:
+ print(ballot.candidates)
+
+
-print(ballot_box.identify_winner(), 'is the winner')
-print(ballot_box.number_rounds, 'rounds of voting were run')
+ print(ballot_box.identify_winner(), 'is the winner')
+ print(ballot_box.number_rounds, 'rounds of voting were run')
+
+if __name__ == '__main__':
+ main(sys.argv[1])

0 comments on commit 0dc36cc

Please sign in to comment.