doodad.util#
Utils for doodad.
Functions
|
Make an object with given string attributes. |
|
Returns a function that checks if an object is an instance of any of the target_types |
- doodad.util.mk_str_attr_obj(iterable, name=None, trans=None)[source]#
Make an object with given string attributes.
The purpose of this function is to offer a different option to having to write strings in code when specifying a string value when this value should only be taken from a fixed set of values, and use tab completion to see the available values.
- Parameters:
>>> f = mk_str_attr_obj('date worker offre success') >>> f.date 'date' >>> f.worker 'worker' >>> f.does_not_exist Traceback (most recent call last): ... AttributeError: 'AttrObj' object has no attribute 'does_not_exist'
fis anamedtupleso you can do things like:>>> list(f) ['date', 'worker', 'offre', 'success'] >>> date, worker, offer, success = f >>> offer 'offre'