Modernize code to Python 3.6+ and some cleanup

This commit is contained in:
Miroslav Šedivý
2021-01-31 22:48:38 +01:00
parent 93bb4407fa
commit b69e0c2023
86 changed files with 153 additions and 189 deletions

View File

@@ -8,7 +8,7 @@ FIRST, LAST = ord(' '), sys.maxunicode # <1>
def find(*query_words, first=FIRST, last=LAST): # <2>
query = {w.upper() for w in query_words} # <3>
count = 0
for code in range(first, last + 1):
for code in range(first, last + 1):
char = chr(code) # <4>
name = unicodedata.name(char, None) # <5>
if name and query.issubset(name.split()): # <6>

View File

@@ -18,4 +18,4 @@ my_file = open('dummy', 'w')
for expression in expressions.split():
value = eval(expression)
print(expression.rjust(30), '->', repr(value))
print(f'{expression:>30} -> {value!r}')

View File

@@ -7,12 +7,12 @@ re_digit = re.compile(r'\d')
sample = '1\xbc\xb2\u0969\u136b\u216b\u2466\u2480\u3285'
for char in sample:
print('U+%04x' % ord(char), # <1>
print(f'U+{ord(char):04x}', # <1>
char.center(6), # <2>
're_dig' if re_digit.match(char) else '-', # <3>
'isdig' if char.isdigit() else '-', # <4>
'isnum' if char.isnumeric() else '-', # <5>
format(unicodedata.numeric(char), '5.2f'), # <6>
f'{unicodedata.numeric(char):5.2f}', # <6>
unicodedata.name(char), # <7>
sep='\t')
# end::NUMERICS_DEMO[]

View File

@@ -11,7 +11,7 @@ text_str = ("Ramanujan saw \u0be7\u0bed\u0be8\u0bef" # <3>
text_bytes = text_str.encode('utf_8') # <5>
print('Text', repr(text_str), sep='\n ')
print(f'Text\n {text_str!r}')
print('Numbers')
print(' str :', re_numbers_str.findall(text_str)) # <6>
print(' bytes:', re_numbers_bytes.findall(text_bytes)) # <7>

View File

@@ -1,4 +1,3 @@
"""
Radical folding and text sanitizing.