Hi!
It is attached on the email, called myprogram.txt
Thank you!
Subject: Re: [Tutor] get columns from txt file
From: dfjenni...@gmail.com
Date: Thu, 12 Jul 2012 11:07:53 -0400
CC: tutor@python.org
To: susana...@hotmail.com
On Jul 12, 2012, at 10:55 AM, susana moreno colomer wrote:
Hi!
I have a group of files in a directory:
bb_1.txt
bb_2.txt
bb_3.txt
bb_4.txt
bb_5.txt
bb_6.txt
ss_1.txt
I want to extract from files whose names start with bb_ column number 5 to
an excel file. I have 6 bb_ files, therefore I want to get 6 columns (5th
column from each file)
This code is working,with the following errors:
I get the data in only one column, instead of six
Great! It sounds like you're almost there. Where's the code which works except
that it puts the data all in one column?
Take care,
Don
#! /usr/bin/env python
import os
import fnmatch
import csv
path = '//../my_working_folder/'
csv_out=csv.writer(open('out14.csv', 'wb'), delimiter=' ')
files=os.listdir(path)
outfile=open('myfile1', 'w')
output=[]
for infile in files:
if fnmatch.fnmatch(infile, 'bb_*'):
filename= os.path.join(path,infile)
f=open(filename, 'r')
for line in f:
b=line.split('\t')
output.append(b[5].strip())
f.close()
########This gives me a single column (I want 6, since I have 6 bb_files:
csv_out.writerows(output)
########with this I get excel whitesheet
def csvwriter():
excelfile=csv_out
a=excelfile.append(output)
c=excelfile.write(a)
return c
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor