diff options
author | Dean Troyer <dtroyer@gmail.com> | 2013-07-16 14:49:54 -0500 |
---|---|---|
committer | Dean Troyer <dtroyer@gmail.com> | 2013-07-18 14:58:02 -0500 |
commit | 3fdc256143d03d2c5b95aab673028b893abeb508 (patch) | |
tree | 3a186e9ef830971264594c87fd146a46e35b8b23 | |
parent | 3c08b794b211ebc018089a74d8af7b9b5489cbb5 (diff) | |
download | cliff-3fdc256143d03d2c5b95aab673028b893abeb508.tar.gz |
Add dict2columns()
Add ShowOne.dict2columns() to handle the common process of displaying
a single dict as two columns of key and value.
-rw-r--r-- | cliff/show.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cliff/show.py b/cliff/show.py index 39e94b1..855b2d2 100644 --- a/cliff/show.py +++ b/cliff/show.py @@ -44,3 +44,12 @@ class ShowOne(DisplayCommandBase): self.app.stdout, parsed_args) return 0 + + def dict2columns(self, data): + """Implement the common task of converting a dict-based object + to the two-column output that ShowOne expects. + """ + if not data: + return ({}, {}) + else: + return zip(*sorted(data.items())) |