-
Notifications
You must be signed in to change notification settings - Fork 34
/
数织.py
49 lines (39 loc) · 1.09 KB
/
数织.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
import re
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-t', type=str, default=None, required=True,
help='输入数织字符串')
args = parser.parse_args()
template = "MK Version 3.0\n\n"
text = args.t
# 1.获取到col和row
col_text = re.findall("col([0-9/()]*)", text)[0]
row_text = re.findall("row([0-9/()]*)", text)[0]
# 2.分割加过滤''
col_lis = col_text.split("/")
col_lis = list(filter(lambda x: x!="", col_lis))
# 3.分割加过滤''
row_lis = row_text.split("/")
row_lis = list(filter(lambda x: x!="", row_lis))
# 4.构造griddler文件
template += f"{len(col_lis)} {len(row_lis)}\n\n"
# 构造 ? 矩阵
for _ in range(len(col_lis)):
for _ in row_lis:
template += " ?"
template += "\n"
template += "\n"
# 构造每列
for col in col_lis:
for j in range(len(col)):
template += f" {col[j]}"
template += "\n"
template += "\n"
# 构造每行
for row in row_lis:
for j in range(len(row)):
template += f" {row[j]}"
template += "\n"
# 5.保存
with open("out.griddler", "w") as f:
f.write(template)