Simplify print_term() and make the output prettier - wr - Translate a term via WordReference.com
(HTM) hg clone https://bitbucket.org/iamleot/wr
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) changeset c9b37cf07c3e0b33a05777eab183f1405f9998bf
(DIR) parent 3b2cf2967a257179ffbe0a02353508f7dcfffc5a
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Tue, 22 Oct 2019 19:35:03
Simplify print_term() and make the output prettier
Diffstat:
wr.py | 31 +++++++++++--------------------
1 files changed, 11 insertions(+), 20 deletions(-)
---
diff -r 3b2cf2967a25 -r c9b37cf07c3e wr.py
--- a/wr.py Mon Oct 21 17:16:53 2019 +0200
+++ b/wr.py Tue Oct 22 19:35:03 2019 +0200
@@ -151,27 +151,18 @@
def print_term(term: Term):
"""Pretty print a Term"""
- sfmt = '{term} '
- if term.term_type:
- sfmt += '[{term_type}] '
- sfmt += '{description}:\n{translations}\n'
-
- translations = ''
+ print('{term} [{term_type}]'.format(
+ term=term.term, term_type=term.term_type))
+ print(' {description}'.format(description=term.term_description))
for translation, translation_type in zip(term.translation, term.translation_type):
- if translations:
- translations += ', '
- translations += '{translation} [{translation_type}]'.format(
- translation=translation,
- translation_type=translation_type)
-
- print(textwrap.fill(sfmt.format(
- term=term.term,
- term_type=term.term_type,
- description=term.term_description,
- translations=translations).strip(),
- width=80,
- break_long_words=False,
- break_on_hyphens=False))
+ print(textwrap.fill('{translation} [{translation_type}]'.format(
+ translation=translation,
+ translation_type=translation_type),
+ initial_indent=' ' * 8,
+ subsequent_indent=' ' * 12,
+ width=80,
+ break_long_words=False,
+ break_on_hyphens=False))
if __name__ == '__main__':