mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
skip all hidden keys, allow exclude list
This commit is contained in:
parent
63df0adc17
commit
f5743396dc
1 changed files with 5 additions and 3 deletions
|
@ -34,8 +34,10 @@ def pct_to_int(value, num_items, min_value=1):
|
|||
return int(value)
|
||||
|
||||
|
||||
def object_to_dict(obj):
|
||||
def object_to_dict(obj, exclude=None):
|
||||
"""
|
||||
Converts an object into a dict making the properties into keys
|
||||
Converts an object into a dict making the properties into keys, allows excluding certain keys
|
||||
"""
|
||||
return dict((key, getattr(obj, key)) for key in dir(obj) if not key.startswith('__'))
|
||||
if exclude is None or not isinstance(exclude, list):
|
||||
exclude = []
|
||||
return dict((key, getattr(obj, key)) for key in dir(obj) if not (key.startswith('_') or key in exclude))
|
||||
|
|
Loading…
Reference in a new issue