[Tutor] how to get blank value

amrita at iisermohali.ac.in amrita at iisermohali.ac.in
Fri Jul 24 11:18:19 CEST 2009


> 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



More information about the Tutor mailing list