输入文件-输入.csv
#######A Result:#########
2016-07-27 bar 51 14
2015-06-27 roujri 30 86
#######B Result:#########
2016-08-26 foo 34 83
2016-08-26 foo 34 83
#########################
输出结果
^{pr2}$我正试图根据上述输入、输出来解决一个问题。到目前为止,我只能阅读第一块文本。我想要更通用的函数,所以我可能只初始化需要在块内读取的变量,而不是硬编码(例如#######A Result:#########
),并进一步将块信息传递给另一个将求和值的函数。如有任何建议,将不胜感激。谢谢:)
import re
def reading_block_text_file(infile):
with open(infile) as fp:
for result in re.findall('#######A Result:#########(.*?)#######B Result:#########', fp.read(), re.S):
print result,
reading_block_text_file(input_file)
加入一点正则表达式:
正则表达式解释:
^{pr2}$Debuggex Demo
相关问题 更多 >
编程相关推荐