Skip to content

Commit

Permalink
utils删除str空白符
Browse files Browse the repository at this point in the history
  • Loading branch information
yjqiang committed Mar 30, 2019
1 parent b42d8c5 commit 5b23548
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import string
from datetime import datetime


Expand All @@ -9,13 +10,22 @@
' ' + ''.join(chr(i) for i in range(65281, 65375))
)

_table_clear_whitespace = str.maketrans('', '', string.whitespace + ' ')


# 中英文对齐(半角转全角)
def hwid2fwid(orig_text, format_control=10):
new_text = orig_text.translate(_table_hwid2fwid)
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
Expand Down

0 comments on commit 5b23548

Please sign in to comment.