[英]How to import string extracted from a file in python?
I have one issue over here in file importing data from text file using python. 我在这里有一个问题是使用python从文本文件导入数据的文件。
I have data like this in my file. 我的文件中有这样的数据。
{1:F05ABCDRPRAXXX0000000000}{2:I1230AGRIXXPRXXXXN}{4:
:20:1234567980
:25:AB123465789013246578900000000000
:28c:110/1123156
-}
So from above data I want to fetch data after {4:
and line by line like first line is :20:1234567980
and so on. 因此,我想从以上数据中提取{4:
之后的数据,并且像第一行一样一行一行地是:20:1234567980
,依此类推。
I want to split data using regular expression So if any python expert have idea how make regular expression for this so provide in answer it will help. 我想使用正则表达式拆分数据,因此,如果有任何python专家有想法如何为此创建正则表达式,请提供答案会有所帮助。
Thank you 谢谢
If you want to get the lines in a file use 如果要获取文件中的行,请使用
lines = list()
with open("yourfiile.txt") as f:
for line in f:
lines.append(line)
lines.pop(0) #remove the first line (which ends with "{4:")
#do what you want with list of lines
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.