Message ID | 1567553238-19549-1-git-send-email-twilson@redhat.com |
---|---|
State | Accepted |
Commit | 6a1c98461b46c407b3513cb6968b02e814ed2f33 |
Headers | show |
Series | [ovs-dev] Add a __str__ method to idl.Row | expand |
On Tue, Sep 03, 2019 at 06:27:18PM -0500, Terry Wilson wrote: > It's sometimes handy to log an entire Row object, so this just > adds a string representation of the object as: > > Tablename(col1=val1, col2=val2, ..., coln=valn) > > Signed-off-by: Terry Wilson <twilson@redhat.com> Applied to master. Thanks!
diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index 84af978..d1d9155 100644 --- a/python/ovs/db/idl.py +++ b/python/ovs/db/idl.py @@ -997,6 +997,12 @@ class Row(object): def __hash__(self): return int(self.__dict__['uuid']) + def __str__(self): + return "{table}({data})".format( + table=self._table.name, + data=", ".join("{col}={val}".format(col=c, val=getattr(self, c)) + for c in sorted(self._table.columns))) + def __getattr__(self, column_name): assert self._changes is not None assert self._mutations is not None
It's sometimes handy to log an entire Row object, so this just adds a string representation of the object as: Tablename(col1=val1, col2=val2, ..., coln=valn) Signed-off-by: Terry Wilson <twilson@redhat.com> --- python/ovs/db/idl.py | 6 ++++++ 1 file changed, 6 insertions(+)