-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword-dir.py
58 lines (52 loc) · 1.28 KB
/
word-dir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
brackets = "〈〉《》「」『』【】〔〕()()"
Widgth = 16
wrev = ""
def isAlnum(word) :
try:
return word.encode(\'utf-8\').isalnum()
except UnicodeEncodeError:
return False
try:
wnum = ""
has_num = 0
wstart = "←"
wline = wstart
nwords = 0
def add_num(wsequence) :
global has_num
if has_num :
global nwords
nwords += has_num
has_num = 0
global wline
wline = wsequence + wline
while True :
str = input("请输入:")
# print("你输入的内容是: ", str, type(str))
for word in str:
i = brackets.find(word)
if (i != -1):
i ^= 1
word = brackets[i:i+1]
if isAlnum(word):
wnum += word
has_num = 1
continue
add_num(wnum)
wnum = ""
wline = word + wline
nwords += 1
if (nwords >= Widgth):
wrev = wrev + wline + "\n"
wline = wstart
nwords = 0
except Exception as err:
print(err)
if nwords or has_num :
add_num(wnum)
wrev += wline
print(wrev)
sys.exit(0)