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