[Tutor] how to get blank value

Alan Gauld alan.gauld at btinternet.com
Tue Jul 28 19:56:02 CEST 2009


<amrita at iisermohali.ac.in> wrote

> Sorry to say, but till now I have not got the solution of my problem, I
> tried with this command:-
>
> import re
>
> if __name__ == '__main__':
>     data = open('chem.txt').readlines()
>     for line in data:
>         RE = re.compile('C = (.)',re.M)

The regex still does not match the end of line.
The regex character for end of line is $ thus you should find something 
like

>         RE = re.compile('C =$')

You might need to allow for whitespace between the = and $...

If the blanks are not at the end of the line things get slightly more
complicated

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list