Re: reading a specific column from file

2008-01-17 Thread John Machin
On Jan 17, 8:47 pm, Hai Vu <[EMAIL PROTECTED]> wrote: > Here is another suggestion: > > col = 2 # third column > filename = '4columns.txt' > third_column = [line[:-1].split('\t')[col] for line in open(filename, > 'r')] > > third_column now contains a list of items in the third column. > > This solu

Re: reading a specific column from file

2008-01-17 Thread Hai Vu
Here is another suggestion: col = 2 # third column filename = '4columns.txt' third_column = [line[:-1].split('\t')[col] for line in open(filename, 'r')] third_column now contains a list of items in the third column. This solution is great for small files (up to a couple of thousand of lines). Fo

RE: reading a specific column from file

2008-01-11 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Ivan Novick > Sent: Friday, January 11, 2008 12:46 PM > To: python-list@python.org > Subject: Re: reading a specific column from file > > > You say you would like

Re: reading a specific column from file

2008-01-11 Thread Ivan Novick
On Jan 11, 4:15 am, cesco <[EMAIL PROTECTED]> wrote: > Hi, > > I have a file containing four columns of data separated by tabs (\t) > and I'd like to read a specific column from it (say the third). Is > there any simple way to do this in Python? You say you would like to "read" a specific column.

Re: reading a specific column from file

2008-01-11 Thread Peter Otten
A.T.Hofkamp wrote: > On 2008-01-11, cesco <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I have a file containing four columns of data separated by tabs (\t) >> and I'd like to read a specific column from it (say the third). Is >> there any simple way to do this in Python? >> >> I've found quite interest

Re: reading a specific column from file

2008-01-11 Thread Fredrik Lundh
cesco wrote: > I have a file containing four columns of data separated by tabs (\t) > and I'd like to read a specific column from it (say the third). Is > there any simple way to do this in Python? use the "split" method and plain old indexing: for line in open("file.txt"): columns = line.s

Re: reading a specific column from file

2008-01-11 Thread Chris
On Jan 11, 2:15 pm, cesco <[EMAIL PROTECTED]> wrote: > Hi, > > I have a file containing four columns of data separated by tabs (\t) > and I'd like to read a specific column from it (say the third). Is > there any simple way to do this in Python? > > I've found quite interesting the linecache module

Re: reading a specific column from file

2008-01-11 Thread A.T.Hofkamp
On 2008-01-11, cesco <[EMAIL PROTECTED]> wrote: > Hi, > > I have a file containing four columns of data separated by tabs (\t) > and I'd like to read a specific column from it (say the third). Is > there any simple way to do this in Python? > > I've found quite interesting the linecache module but