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 and 
6. I want to extract all columns number 5 to one file, and all tcolumns number6 
to another file. 
I was following this example 
http://mail.python.org/pipermail/tutor/2009-February/067400.html , and I 
created my own code wich gives me the following errors:
 

This code gives me 2 files:
                ro with 2 lines
                bf emty
 
I attached my code, with two options (though I was trying wich much more)
Could be awesome If I extrace them in an excel file, Any suggestion????
 
Many thanks!!!
Susana                                    
#! /usr/bin/env python
#-*- coding: utf -8 -*-


import os
import fnmatch
import csv

path = '//../my_working_folder/'

files=os.listdir(path)
ro=[]; bf=[]
A=[]; B=[]

for infile in files:
        if fnmatch.fnmatch(infile, 'bb_*'):
                filename= os.path.join(path,infile)
                f=open(filename, 'r')

##########OPTION ONE            
                for line in f.readlines():
                        b=line.split('\t')
                        for b in line:
                                A.extend('\t'.join.b[5])
                                B.extend('\t'.join.b[6])
                ro.extend(A)
                bf.extend(B)
                f.close()

                lists=[(ro, 'ro'), (bf, 'bf')]
                for values, name in lists:
                        output=open( name + '.txt',  'w')
                        for value in values:
                                output.write(str(values))
                                output.write('\n')
                                output.close
                

##########OPTION TWO
                
for line in f.readlines():
                        
                        b=line.split('\t')
                        A.extend(b[5])
                        B.extend(b[6])
        ro.extend(A)
        bf.extend(B)
        
#the same: I get Syntaxerror:invalid syntax
        
        lists=[(ro, 'ro'), (bf, 'bf')]
        for values, name in lists:
                output=open( name + '.txt',  'w')
                for value in values:
                        output.write(str(values))
                        output.write('\n')

                output.close()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to