Skip to content

Instantly share code, notes, and snippets.

@jwestgard
Last active October 12, 2019 13:05
Show Gist options
  • Select an option

  • Save jwestgard/2646939eb5e0bc204ee02ac7e288bd4d to your computer and use it in GitHub Desktop.

Select an option

Save jwestgard/2646939eb5e0bc204ee02ac7e288bd4d to your computer and use it in GitHub Desktop.
state class example
import csv
class State():
def __init__(self, row):
self.abbrev = row["State"]
self.mwh = row["Megawathours"]
self.source = row["Energy Source"]
self.year = row["Year"]
def main():
fh = open('/Users/tmgre/Downloads/energy.csv')
spreadsheet = csv.reader(fh)
greatest_wind = None
for row in spreadsheet:
if row[2] == 'Wind':
current_state = State(row)
if greatest_wind is None or greatest_wind.mwh < current_state.mwh:
greatest_wind = current_state
elif row[2] == 'Solar Thermal and Photovoltaic':
#### etc. ####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment