-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
67 lines (63 loc) · 1.68 KB
/
Copy pathexample.py
File metadata and controls
67 lines (63 loc) · 1.68 KB
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
59
60
61
62
63
64
65
66
67
# from ply import lex
#
# tokens = (
# "SYMBOL",
# "COUNT"
# )
#
# t_SYMBOL = (
# r"C[laroudsemf]?|Os?|N[eaibdpos]?|S[icernbmg]?|P[drmtboau]?|"
# r"H[eofgas]?|A[lrsgutcm]|B[eraik]?|Dy|E[urs]|F[erm]?|G[aed]|"
# r"I[nr]?|Kr?|L[iaur]|M[gnodt]|R[buhenaf]|T[icebmalh]|"
# r"U|V|W|Xe|Yb?|Z[nr]"
# )
#
# def t_COUNT(t):
# r"\d+"
# t.value = int(t.value)
# return t
#
# def t_error(t):
# raise TypeError("Unknown text '%s'" % (t.value,))
#
# lex.lex()
#
# lex.input("CH3COOH")
# for tok in iter(lex.token, None):
# print (repr(tok.type), repr(tok.value))
# f = (0x0, 0xff, 0x7f, 0x47)
# for i in f:
# print(float(i))
#
# f = "0x0f.43"
# print((f,16))
# 十六进制/十进制 转换器
# 可兼容十六进制小数转换
def hex_to_dec(string):
# 定位到'.'的位置
pos = str(string).find('.')
# 如果定位小于 0 (即没有找到小数点), 则证明这是整数
if pos < 0:
# 直接调用整型转换
return int(string,16)
else:
# 如果确实是十六进制小数, 则整数部分和小数部分分别转化
# 先以小数点为标志, 对两部分进行切分
stringA = string[ : pos]
stringB = string[pos+1 : ]
counter = 1
# 对整数部分直接转换
sumA = int(stringA,16)
sumB = 0
# 对小数部分按照十六进制的规则进行转换: 16分位、256分位……
for digit in stringB:
sumB = sumB + (int(digit,16) / pow(16,counter))
counter += 1
# 返回整数部分和小数部分的相加结果
return sumA + sumB
# print (hex_to_dec('0xaa.11'))
a = [0,]
b = [1,]
t = (a,b,)
a.append(2)
print(t)