[Tutor] how to get blank value

Luke Paireepinart rabidpoobear at gmail.com
Fri Jul 24 12:41:41 CEST 2009


You will probably continue to get unsatisfactory responses if you continue
to ask unsatisfactory questions.Python won't automatically parse this
document in exactly the way you want it to.  You're on the right track but
you need to do as Alan said and actually read the regex articles to
understand how they work.

On Fri, Jul 24, 2009 at 4:18 AM, <amrita at iisermohali.ac.in> wrote:

>
> > What is the python command for searching blank value of a parameter?
>
> > Please use Reply All to send it to the list as well.
> >
> >
> >> I am trying it in this way also:---
> >>
> >> import re
> >> expr = re.compile("C")
> >
> > This will find all lines with the letter C in them.
> > Which from your data is all of them. Look at the regex documentation
> > to see how to represent the end of a line (or, slightly more complex,  a
> > non digit).
> >
> >> f = open('chem.txt')
> >> for line in f:
> >>     expr.search(line)
> >>         if 'C = '
> >
> >
> > This is invalid Python, the second level of indentation should produce an
> > error!
> > Also you are not doing anything with the result of your search, you just
> > throw
> > it away.
> >
> > You need something like
> >
> > for line in open('chem.txt'):
> >     if expr.search(line):
> >        print line
> >
> >
> > HTH,
> >
> > Alan g.
> >
> >> > wrote
> >> >
> >> >> 48 ALA H = 8.33 N = 120.77 CA = 55.18 HA = 4.12 C = 181.50
> >> >> 104 ALA H = 7.70 N =  CA =  HA = 4.21 C =
> >> >>
> >> >> Now i want to make two another file in which i want to put those
> >> lines
> >> >> for
> >> >> which C is missing and another one for which N,CA and C all are
> >> missing,
> >> >>
> >> >> I tried in this way:
> >> >> import re
> >> >> expr = re.compile("C = None")
> >> >
> >> > This will search for the literal string 'C = None' which does not
> >> exist in
> >> > your sdata.
> >> > You need to search for 'C = 'at the end of the line (assuming it is
> >> always
> >> > there.
> >> > Otherwise you need to search for 'C = ' followed by a non number.)
> >> >
> >> > HTH,
> >> >
> >> > --
> >> > Alan Gauld
> >> > Author of the Learn to Program web site
> >> > http://www.alan-g.me.uk/
> >> >
> >> >
> >> > _______________________________________________
> >> > Tutor maillist  -  Tutor at python.org
> >> > http://mail.python.org/mailman/listinfo/tutor
> >> >
> >>
> >>
> >> Amrita Kumari
> >> Research Fellow
> >> IISER Mohali
> >> Chandigarh
> >> INDIA
> >
> >
>
>
> Amrita Kumari
> Research Fellow
> IISER Mohali
> Chandigarh
> INDIA
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090724/1c4a99e8/attachment.htm>


More information about the Tutor mailing list