re.search question

Sean 'Shaleh' Perry shalehperry at attbi.com
Thu Aug 1 00:28:37 CEST 2002


On 31-Jul-2002 michaelian ennis wrote:
> How would I tell python to give me all the text in a string which
> falls between  the first instance of "!" alone on a line and the first
> instance of "end" alone on a line inclusively?
> 
> 
> lines=
> junk 
> !
> important stuff
> end
> more junk
> 
> 
> to 
> 
> cleaned_lines=
> !
> important stuff
> end
> 

Why use a regex here?

NOT_READY, READY = (0, 1)

print '!'
for line in input:
    if line == '!':
        state = READY
    elif line == 'end':
        state = NOT_READY:
    elif state == READY:
        print line
print 'end'





More information about the Python-list mailing list