how to get no value

Grant Edwards invalid at invalid
Fri Jul 24 16:10:29 CEST 2009


On 2009-07-24, amrita at iisermohali.ac.in <amrita at iisermohali.ac.in> wrote:
>
> Hi,
>
> I have a file having lines:-
>
> 48 ALA H = 8.33 N = 120.77 CA = 55.18 HA = 4.12 C = 181.50
> 104 ALA H = 7.70 N = 121.21 CA = 54.32 HA = 4.21 C =
> 85 ALA H = 8.60 N =  CA =  HA = 4.65 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
> f = open('chem.txt')
> for line in f:
>      if re.search('C = ',''):
>         print line
>
> but i am not getting the desired output.

I've told you before: don't use regular expressions (e.g. the
"re" module).  Stop using regular expressions now.  Regular
expressions are way beyond your capabilities.  

Use simple operations like split() and "in":

  f = open('chem.txt')
  for line in f:
    if "C = " in line:
      print line
      
You really need to work through a Python tutorial or two:

  http://docs.python.org/tutorial/
  http://www.greenteapress.com/thinkpython/thinkpython.html

Better yet, take an couple introductory programming courses.

I'm a bit surprised that one could become a "Research Fellow"
in a scientific field without taking any programming courses.

-- 
Grant Edwards                   grante             Yow! I'm also against
                                  at               BODY-SURFING!!
                               visi.com            



More information about the Python-list mailing list