在完成数据提取功能的最后几天,我们一直在学习Python。我没有得到任何地方&希望你们中的一个可爱的人可以建议。如何从电子素数输出(.txt文件)中提取特定数据
我需要提取以下数据:RESP,CRESP,RTTime和RT。
下面是我必须处理的一个混乱的例子snippit。
想法?
Level: 4
*** LogFrame Start ***
Procedure: ActProcScenarios
No: 1
Line1: It is almost time for your town's spring festival. A friend of yours is
Line2: on the committee and asks if you would be prepared to help out with the
Line3: barbecue in the park. There is a large barn for use if it rains.
Line4: You hope that on that day it will be
pfrag: s-n-y
pword: sunny
pletter: u
Quest: Does the town have an autumn festival?
Correct: {LEFTARROW}
ScenarioListPract: 1
Topic: practice
Subtheme: practice
ActPracScenarios: 1
Running: ActPracScenarios
ActPracScenarios.Cycle: 1
ActPracScenarios.Sample: 1
DisplayFragInstr.OnsetDelay: 17
DisplayFragInstr.OnsetTime: 98031
DisplayFragInstr.DurationError: -999999
DisplayFragInstr.RTTime: 103886
DisplayFragInstr.ACC: 0
DisplayFragInstr.RT: 5855
DisplayFragInstr.RESP: {DOWNARROW}
DisplayFragInstr.CRESP:
FragInput.OnsetDelay: 13
FragInput.OnsetTime: 103899
FragInput.DurationError: -999999
FragInput.RTTime: 104998
嗨,欢迎来到StackOverflow。我冒着重新格式化你的文章的自由 - 这是否正确?另外,您能否告诉我们您遇到问题的哪个部分?读文件?找到正确的线?在这些方面找到相关的价值观?包含您已有的代码总是很好,所以我们可以显示哪些部件需要工作... –
这是完美的谢谢你,谢谢你的回答! 我了解您提供的代码的功能,但是我在实施时遇到了问题。 我显然必须阅读所需的.txt文件: ep = open('t1.txt。') 然后确定它应该是运行代码并将myfile替换为'ep'的问题。我是否缺少重要的基础知识,因为没有任何反应? 谢谢你的耐心:) – user3042303
你的方法对我来说看起来是正确的。正则表达式相当严格,因为它需要在冒号后面有一个空格字符;如果这不存在(或者可能是一个选项卡),那么正则表达式不匹配。也许在匹配它们之前尝试“打印”这些行,看看这个文件是否真的包含你认为它的内容,并且Python正确地读取它。 –