From 5b23548e808d79102d97348f29104ae4e234d1e0 Mon Sep 17 00:00:00 2001 From: yjqiang Date: Sun, 31 Mar 2019 00:00:42 +0800 Subject: [PATCH] =?UTF-8?q?utils=E5=88=A0=E9=99=A4str=E7=A9=BA=E7=99=BD?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils.py b/utils.py index a9afac7..f3f5a20 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,5 @@ import time +import string from datetime import datetime @@ -9,6 +10,8 @@ ' ' + ''.join(chr(i) for i in range(65281, 65375)) ) +_table_clear_whitespace = str.maketrans('', '', string.whitespace + ' ') + # 中英文对齐(半角转全角) def hwid2fwid(orig_text, format_control=10): @@ -16,6 +19,13 @@ def hwid2fwid(orig_text, format_control=10): return f'{new_text: ^{format_control}}' +def clear_whitespace(orig_text, more_whitespace: str = ''): + if not more_whitespace: + return orig_text.translate(_table_clear_whitespace) + return orig_text.translate(_table_clear_whitespace).\ + translate(str.maketrans('', '', more_whitespace)) + + def seconds_until_tomorrow(): dt = datetime.now() return (23 - dt.hour) * 3600 + (59 - dt.minute) * 60 + 60 - dt.second