我想在两行之间提取数据,我有不同模式的文本文件,我有python代码,用于数字,但不用于文本,所以我需要帮助
我的文本文件格式1
TAX INVOICE (Under Rule 46 of the Central Goods & Service Tax Rules, 2017)
ANURAG ENTERPRISES ANURAG ENTERPRISES, VEDAVATHI NAGAR,CHALLAKERE ROAD HIRIYUR
State Code: 29
我的文本文件格式2
Page 1 of 1
KS LINGAPPA AND SON Industrial Area, Plot No 14. KSSIDC TBDam Road, Hosapete-583201 State Karnataka
State Code 29
我想要的输出
1.ANURAG ENTERPRISES ANURAG ENTERPRISES
2.KS LINGAPPA AND SON
for name in files:
with open(name, encoding="utf8") as infile:
copy = False
cnt=0
for line in infile:
if line.strip()=="Page":
copy = True
continue
if line.strip()=="TAX":
copy = True
continue
elif line.strip() == "State":
copy = False
continue
elif copy:
print(line)
正如Onno Rouast所评论的,提取规则是什么并不十分清楚。下面的两个例子都适用,但谁能说未来会带来什么呢
Regex Demo
印刷品:
更新
相关问题 更多 >
编程相关推荐