Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to get no value

0 views
Skip to first unread message

amr...@iisermohali.ac.in

unread,
Jul 24, 2009, 6:20:11 AM7/24/09
to pytho...@python.org

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.


Amrita Kumari
Research Fellow
IISER Mohali
Chandigarh
INDIA

Diez B. Roggisch

unread,
Jul 24, 2009, 6:56:16 AM7/24/09
to
amr...@iisermohali.ac.in schrieb:

> 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.


Gosh. Must be groundhog-day. Again.

And there is me thinking that my job could be endangered by cheap &
qualified indian soft-workers - can't be to many of them around if the
OP doesn't get a hold of one for the better part of a month now. Must be
one of those management myths they tell you to scare you into a less
well paid contract...

Diez

D'Arcy J.M. Cain

unread,
Jul 24, 2009, 6:56:03 AM7/24/09
to amr...@iisermohali.ac.in, pytho...@python.org
On Fri, 24 Jul 2009 15:50:11 +0530 (IST)
amr...@iisermohali.ac.in wrote:
> but i am not getting the desired output.

Show us what output you got and what you desired.

--
D'Arcy J.M. Cain <da...@druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

Piet van Oostrum

unread,
Jul 24, 2009, 7:48:09 AM7/24/09
to
>>>>> amr...@iisermohali.ac.in (a) a �crit:

>a> Hi,

>a> I have a file having lines:-

>a> 48 ALA H = 8.33 N = 120.77 CA = 55.18 HA = 4.12 C = 181.50
>a> 104 ALA H = 7.70 N = 121.21 CA = 54.32 HA = 4.21 C =
>a> 85 ALA H = 8.60 N = CA = HA = 4.65 C =

>a> Now i want to make two another file in which i want to put those lines for
>a> which C is missing and another one for which N,CA and C all are missing,

>a> I tried in this way:
>a> import re
>a> f = open('chem.txt')
>a> for line in f:
>a> if re.search('C = ',''):
>a> print line

>a> but i am not getting the desired output.

You never look in the lines you read.
if re.search('C = ',''): should be
if re.search('C = ', line):

Do you really think before you write your code? Or look at it after you
have written it?

Sorry if I offend you but you give the impression of just trying some
more or less random stuff and then asking here if it doesn't give the
required result.

That's not the attitude of a researcher, unless your definition of
research is 'asking on Usenet'.
--
Piet van Oostrum <pi...@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: pi...@vanoostrum.org

Mark Lawrence

unread,
Jul 24, 2009, 9:50:33 AM7/24/09
to pytho...@python.org
amr...@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.
>
>
>
>
> Amrita Kumari
> Research Fellow
> IISER Mohali
> Chandigarh
> INDIA
>
Try writing correct rather than incorrect code. Or as has been
repeatedly stated get somone from your CS department to help.


--

Kindest regards.

Mark Lawrence.

Grant Edwards

unread,
Jul 24, 2009, 10:10:29 AM7/24/09
to
On 2009-07-24, amr...@iisermohali.ac.in <amr...@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

Piet van Oostrum

unread,
Jul 24, 2009, 11:06:23 AM7/24/09
to
Well actually your subject is `how to get no value'. Your code does that
perfectly. :=)
0 new messages