コード例 #1
0
 def setUp(self):
     self.results = ElectionResults('election_results_test_file.csv')
コード例 #2
0
# Election Results module
# Coded in the "object-oriented" style
from electiondata import ElectionResults
state_arr[], obama_tot=0, romney_tot=0, 
filename = '2012_US_election_state.csv'
results = ElectionResults(filename)
results.load()

function state_names() {
	state_arr[]=results.states()
	return state_arr
}
print "done ("+str(results.state_count())+" lines)"

# print total votes per candidate
コード例 #3
0
# Print out all the state names from the csv
# Coded in the "object-oriented" style
from electiondata import ElectionResults
filename = '2012_US_election_state.csv'
results = ElectionResults(filename)
results.load()
print "Opened file:"
state_names = results.states()
for state in state_names:
    print "  "+state
print "done ("+str(results.state_count())+" lines)"
コード例 #4
0
# Print out all the state names from the csv
# Showing an "event-driven" style
from electiondata import ElectionResults
import sys
filename = '2012_US_election_state.csv'
results = ElectionResults(filename)
while True:
    command = raw_input('Enter your input (1 to load, 2 to print, 3 to quit):')
    if command=="1":
        results.load();
        print "Loaded ("+str(results.state_count())+" lines)"
    elif command=="2":
        state_names = results.states()
        for state in state_names:
            print "    "+state
    elif command=="3":
        print "bye!"
        sys.exit()
    else:
        print "Uknown command :-("