Skip to content

Instantly share code, notes, and snippets.

@jaapz
Last active December 30, 2015 11:19
Show Gist options
  • Save jaapz/7822021 to your computer and use it in GitHub Desktop.
Save jaapz/7822021 to your computer and use it in GitHub Desktop.
class Compri(object):
# De plek waarop de naam van het veld in deze lijst staat komt overeen met de plek waarop het in het 'parts' text staat. Dus
# slotactie staat op positie 0 in parts, perstijd1 op positie 1 in parts, etc.
_name_to_number_map = ['slotactie', 'perstijd1', 'tijdstemp1', ...]
def __init__(self, parts):
self.fill_with_parts_data(parts)
def fill_with_parts_data(self, parts):
""" Fills fields on this class with the data in parts.
This method uses the _name_to_number_map field to see which field maps to which position in parts.
"""
for field_name in self._name_to_number_map:
try:
setattr(self, field_name, parts[self._name_to_number_map.index(field_name)]
except IndexError:
print 'Something went completely wrong when trying to get the %s field' % field_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment