在完成數據提取功能的最後幾天,我們一直在學習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正確地讀取它。 –