how to extract columns like awk $1 $5

2005-01-07 Thread Anand S Bisen
Hi Is there a simple way to extract words speerated by a space in python the way i do it in awk '{print $4 $5}' . I am sure there should be some but i dont know it. Thanks n00b -- http://mail.python.org/mailman/listinfo/python-list

Re: how to extract columns like awk $1 $5

2005-01-07 Thread Craig Ringer
On Sat, 2005-01-08 at 01:15, Anand S Bisen wrote: Hi Is there a simple way to extract words speerated by a space in python the way i do it in awk '{print $4 $5}' . I am sure there should be some but i dont know it. The 'str.split' method is probably what you want: . x = The confused frog

Re: how to extract columns like awk $1 $5

2005-01-07 Thread beliavsky
It takes a few more lines in Python, but you can do something like for text in open(file.txt,r): words = text.split() print words[4],words[5] (assuming that awk starts counting from zero -- I forget). -- http://mail.python.org/mailman/listinfo/python-list

Re: how to extract columns like awk $1 $5

2005-01-07 Thread Jeremy Sanders
On Fri, 07 Jan 2005 12:15:48 -0500, Anand S Bisen wrote: Is there a simple way to extract words speerated by a space in python the way i do it in awk '{print $4 $5}' . I am sure there should be some but i dont know it. mystr = '1 2 3 4 5 6' parts = mystr.split() print parts[3:5] Jeremy --

Re: how to extract columns like awk $1 $5

2005-01-07 Thread Roy Smith
In article [EMAIL PROTECTED], Anand S Bisen [EMAIL PROTECTED] wrote: Hi Is there a simple way to extract words speerated by a space in python the way i do it in awk '{print $4 $5}' . I am sure there should be some but i dont know it. Something along the lines of: words = input.split() print

Re: how to extract columns like awk $1 $5

2005-01-07 Thread Paul Rubin
[EMAIL PROTECTED] (Roy Smith) writes: Something along the lines of: words = input.split() print words[4], words[5] That throws an exception if there are fewer than 6 fields, which might or might not be what you want. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to extract columns like awk $1 $5

2005-01-07 Thread Dan Valentine
On Fri, 07 Jan 2005 12:15:48 -0500, Anand S Bisen wrote: Is there a simple way to extract words speerated by a space in python the way i do it in awk '{print $4 $5}' . I am sure there should be some but i dont know it. i guess it depends on how faithfully you want to reproduce awk's

Re: how to extract columns like awk $1 $5

2005-01-07 Thread Roy Smith
Dan Valentine [EMAIL PROTECTED] wrote: On Fri, 07 Jan 2005 12:15:48 -0500, Anand S Bisen wrote: Is there a simple way to extract words speerated by a space in python the way i do it in awk '{print $4 $5}' . I am sure there should be some but i dont know it. i guess it depends on how

Re: how to extract columns like awk $1 $5

2005-01-07 Thread Carl Banks
Roy Smith wrote: Hmmm. There's something going on here I don't understand. The ref manual (3.3.5 Emulating container types) says for __getitem__(), Note: for loops expect that an IndexError will be raised for illegal indexes to allow proper detection of the end of the sequence. I expected