我有以下“greekSymbols.txt”
Α α alpha
Β β beta
Γ γ gamma
Δ δ delta
Ε ε epsilon
Ζ ζ zeta
Η η eta
Θ θ theta
Ι ι iota
Κ κ kappa
Λ λ lambda
Μ μ mu
Ν ν nu
Ξ ξ xi
Ο ο omicron
Π π pi
Ρ ρ rho
Σ σ sigma
Τ τ tau
Υ υ upsilon
Φ φ phi
Χ χ chi
Ψ ψ psi
Ω ω omega
我试图将其转换为带有标签作为分隔符的 Anki 纯文本文件。我将每一行转换为两张卡片,其中前面是符号(大写或小写),后面是名称。我有以下。
#!/usr/local/bin/python
import re
pattern = re.compile(r"(.)\s+(.)\s+(.+)", re.UNICODE)
input = open("./greekSymbols.txt", "r")
output = open("./greekSymbolsFormated.txt", "w+")
line = input.readline()
while line:
string = line.rstrip()
m = pattern.match(string)
if m:
output.write(m.group(1) + "\t" + m.group(3) + "\n")
output.write(m.group(2) + "\t" + m.group(3) + "\n")
else:
print("I was unable to process line '" + string + "' [" + str(m) + "]")
line = input.readline()
input.close();
output.close();
不幸的是,我目前每行都收到“我无法处理...”消息,str(m) 的值为 None。我究竟做错了什么?
> localhost:Anki stephen$ python ./convertGreekSymbols.py
I was unable to process line 'Α α alpha' [None]
I was unable to process line 'Β β beta' [None]
...