通过关键字解析文件
帮助Python中文件的解析器。有一个带有内容的文件:
============ | another peace mushroom enroll point trip sort notice hobby bacon exact slab | 0xb34a47885262f9d8673dc77de7b583961134f09fb03620b29d282c32ee6932be | 0xD0b2612a6eE3111114b43b25322C6F08A251D38D | Total: 47.62874464666479$ | | | Tokens eth: | 20.608732$ MANA | | Protocols cro: | 17.840052$ VVS Finance | 8.953779$ V3S Finance
============ | road vocal tissue faint wonder host forget canvas jump brisk latin trigger | 0x72e164aa187feaff7cb28a74b7ff800a0dfe916594c70f141069669e9df5a23b | 0xC7dFe558ed09F0f3b72eBb0A04e9d4e99af0bd0D | Total:
22.908481672796988$ | | | Tokens eth: | 22.376087$ SOS
============ | spend easy harsh benefit correct arch draft similar music car glad roof | 0xbce666bca3c862a2ee44651374f95aca677de16b4922c6d5e7d922cc0ac42a3d | 0x5870923a244f52fF2D119fbf5525421E32EC006e | Total: 9.077030269778557$ | | | Tokens eth: | 8.942218$ SOS
============
字符串中的分离器是字符=====================将感谢您的帮助! 从代码中,我尝试了此选项,但是我需要符号===之间的剩余值,前提是总计大于20。
with open('total.txt') as file:
data_file = file.readlines()
# print(data_file)
for i in data_file:
replace_data = i.strip('| ')
replace_space = replace_data.strip('\n')
remove_whitespace = replace_space.strip('\n')
if 'Total:' in remove_whitespace:
print(remove_whitespace)
help with the parser of the file in python. There is a file with content:
============ | another peace mushroom enroll point trip sort notice hobby bacon exact slab | 0xb34a47885262f9d8673dc77de7b583961134f09fb03620b29d282c32ee6932be | 0xD0b2612a6eE3111114b43b25322C6F08A251D38D | Total: 47.62874464666479$ | | | Tokens eth: | 20.608732$ MANA | | Protocols cro: | 17.840052$ VVS Finance | 8.953779$ V3S Finance
============ | road vocal tissue faint wonder host forget canvas jump brisk latin trigger | 0x72e164aa187feaff7cb28a74b7ff800a0dfe916594c70f141069669e9df5a23b | 0xC7dFe558ed09F0f3b72eBb0A04e9d4e99af0bd0D | Total:
22.908481672796988$ | | | Tokens eth: | 22.376087$ SOS
============ | spend easy harsh benefit correct arch draft similar music car glad roof | 0xbce666bca3c862a2ee44651374f95aca677de16b4922c6d5e7d922cc0ac42a3d | 0x5870923a244f52fF2D119fbf5525421E32EC006e | Total: 9.077030269778557$ | | | Tokens eth: | 8.942218$ SOS
============
The separators in the strings are the characters ============ and I need to parse these strings, and output only the data between characters where Total is greater than 20. I will be grateful for help!
From the code I tried this option, but I need the remaining values between the signs === provided that Total is greater than 20.
with open('total.txt') as file:
data_file = file.readlines()
# print(data_file)
for i in data_file:
replace_data = i.strip('| ')
replace_space = replace_data.strip('\n')
remove_whitespace = replace_space.strip('\n')
if 'Total:' in remove_whitespace:
print(remove_whitespace)
there all the values on a new line, an example in the photo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
逐行消耗文件。如果一条线以“ =”开头,那么您将开始一个新的部分,在这种情况下,您需要检查以前构建的行列表,还检查是否发现了总数大于20。
尝试以下操作:
Consume the file line by line. If a line starts with '=' then you're starting a new section in which case you need to check the list of lines you've previously built up and also check to see if a Total was found greater than 20.
Try this: