简体   繁体   English

如何导入从python中的文件中提取的字符串?

[英]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.

相关问题 如何在python中解码从网站提取的pfd文件? - How to decode a extracted pfd file from a website in python? 清理从csv文件提取的字符串 - Clean up string extracted from csv file 如何在python中将正则表达式提取的字符串转换为整数? - How to convert string extracted by regex to integer in python? 将从 python 字典中提取的信息写入文件 - Writing extracted information from python dictionary to a file 从 python 中的不同文件导入字符串 - import string from different file in python 如何将从 salesforce 中提取的表格式化为 python? - How to format a table extracted from salesforce into python? 如何从csv文件提取的字符串中删除变化的多个字符串 - How to remove varying multiple strings from a string extracted from a csv file 如何从文本文件中获取数据,然后在 Python 文件中使用提取的数据? - How do you grab data from a text file, then use the extracted data in the Python file? 如何基于从python中的字符串中提取的数值以降序对记录进行排序? - How do I sort records in descending order based on a extracted numerical value from a string in python? 如何在 python 中将从字符串中提取的数据的数据类型更改为货币或十进制 - How can I change the data type of data that is being extracted from string to money or decimal in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM