how can I express this idea in Pythonic way? The problem is that I want to create class with many attributes, but don't want to initialize all in __init__(self, arg1, arg2, ..., argN). Instead of this I want use some like this:
class DummyUpdater(object):
def from_dict(self, d):
self.__dict__.update(d)
return self
def __repr__(self):
attributes = inspect.getmembers(self.__class__, lambda a: not(inspect.isroutine(a)))
return '{}'.format({a[0]: getattr(self, a[0]) for a in attributes if not(a[0].startswith('__') and a[0].endswith('__'))})
class Passenger(DummyUpdater):
"""docstring for Passenger"""
first_name = ''
last_name = ''
middle_name = ''
title = ''
maturity = ''
document_number = ''
document_type = ''
What is used now (with dummy updater):
passenger = Passenger().from_dict({'first_name' : 'Name', ...})
What I want to achive:
passenger = Passenger({'first_name' : 'Name', ...})
# and when I print passenger object I want see
print(passenger) # {'first_name' : 'Name', ...}
Passenger
. Also, can you fix your docstring. \$\endgroup\$