How to check using findall in text file using Python?
<p>I wrote a function to extract a pattern from a file, but it didn't work right. Why?</p>

<p>My code in <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="nofollow">Python</a>:</p>

<pre><code>import re

f = open('quran_final.txt','r')
r = open('q.txt','w')
p = re.compile('ROOT:(?P&lt;root&gt;[^ "]+)')
for line in f:
    root = p.findall(line)
    if(root):
        for word in root:
        print word
    else:
        print ' '
</code></pre>

<p>I think the problem is in the "check", but how should I change it?</p>

<p>My text file sample:</p>

<pre><code>f:CONJ+ POS:V IMPV ROOT:Akl 2MP  
POS:LOC LEM:Hayov ROOT:Hyv  
POS:V PERF ROOT:$yA 2MP  
POS:ADJ LEM:ragad ROOT:rgd M INDEF ACC  
wa+ POS:V IMPV ROOT:dxl 2MP  
Al+ POS:N LEM:baAb ROOT:bwb M ACC  
POS:N LEM:saAjid ROOT:sjd MP INDEF ACC  
wa+ POS:V IMPV ROOT:qwl 2MP  
POS:N LEM:HiT~ap ROOT:HTT F INDEF NOM  
POS:V IMPF ROOT:gfr 1MP MOOD:JUS  
POS:N LEM:xaTiy^_#ap ROOT:xTA P ACC PRON:2MP  
wa+ sa+ POS:V IMPF ROOT:zyd 1MP  
Al+ POS:N ACT PCPL (IV) LEM:muHosin ROOT:Hsn MP ACC  
f:REM+ POS:V PERF (II) ROOT:bdl 3MS  
POS:V PERF ROOT:Zlm 3MP  
POS:N LEM:qawol ROOT:qwl M INDEF ACC  
POS:REL LEM:{l~a*iY MS  
POS:V PERF PASS ROOT:qwl 3MS  
f:REM+ POS:V PERF (IV) ROOT:nzl 1MP  
POS:REL LEM:{l~a*iY MP  
POS:V PERF ROOT:Zlm 3MP  
POS:N LEM:rijoz ROOT:rjz M INDEF ACC  
Al+ POS:N LEM:samaA^' ROOT:smw F GEN  
POS:V PERF ROOT:kwn SP:kaAn 3MP  
POS:V IMPF ROOT:fsq 3MP  
POS:V PERF (X) ROOT:sqy 3MS  
</code></pre>
