From fb8b3000cf8860a5ca3a49927c805f9912ce9b3b Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Thu, 21 Mar 2024 06:35:37 +0100 Subject: [PATCH 1/2] fix: [main] make it functional under Python 3 --- nato_converter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nato_converter.py b/nato_converter.py index 07a4b88..13d7be0 100755 --- a/nato_converter.py +++ b/nato_converter.py @@ -3,7 +3,6 @@ import sys - table = { "a": "alpha", "b": "bravo", @@ -84,8 +83,8 @@ if __name__ == '__main__': orig = orig.replace("\n", " ") result = convert(orig) - print "%s: %s" % (orig, result) + print(f'{orig}:{result}') else: - print "usage" + print("usage") # vim: set ts=4 sw=4 expandtab: From 552d5a29925793333469c5ac7b6bfa62223b4f02 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Thu, 21 Mar 2024 06:38:49 +0100 Subject: [PATCH 2/2] chg: [main] black it --- nato_converter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nato_converter.py b/nato_converter.py index 13d7be0..dc2e4fc 100755 --- a/nato_converter.py +++ b/nato_converter.py @@ -39,20 +39,23 @@ table = { "6": "Soxisix", "7": "Setteseven", "8": "Oktoeight", - "9": "Novenine" - } + "9": "Novenine", +} + class IllegalStringSize(Exception): def __init__(self, msg): super(Exception, self).__init__(msg) + def find_in_table(letter): if len(letter) != 1: raise IllegalStringSize( - "The letter parameter should only contains one character") + "The letter parameter should only contains one character" + ) if letter in table: - res = table[letter] + res = table[letter] elif letter.lower() in table: res = table[letter.lower()].upper() elif not letter or letter.isspace(): @@ -61,6 +64,7 @@ def find_in_table(letter): res = letter return res + def convert(orig): result = "" for letter in orig: @@ -71,6 +75,7 @@ def convert(orig): result = res return result + if __name__ == '__main__': orig = "" if len(sys.argv) > 1: