[Tutor] Need URGENT support ... PL
nitin chandra
nitinchandra1 at gmail.com
Wed Aug 25 21:40:33 CEST 2010
Hi all,
I have been getting support on this from the list, but unfortunately
now it has become URGENT that i get some solution to this problem i
need to resolve.
What i have done is create FileA.CSV whose structure is as follows :-
(no blank spaces, this is just for representation)
/home/nitin/path/To/PRl1/File1.csv , /home/nitin/path/To/PR3/File1.csv
, /home/nitin/path/To/PR2/File1.csv
/home/nitin/path/To/PRl1/File2.csv , /home/nitin/path/To/PR3/File2.csv
, /home/nitin/path/To/PR2/File2.csv
/home/nitin/path/To/PRl1/File3.csv , /home/nitin/path/To/PR3/File3.csv
, /home/nitin/path/To/PR2/File3.csv
/home/nitin/path/To/PRl1/File4.csv , /home/nitin/path/To/PR3/File4.csv
, /home/nitin/path/To/PR2/File4.csv
...
...
(96) rows
The first column is INPUT Protocol-1 File1
Second Column is INPUT Protocol-3 File1
Third Column is OUTPUT Protocol-2 File1
Each File (eg. PR1/File1 , PR3/File1 ) have approx. 600 rows of 39
column, numeric data. These data files end in a blank new line / blank
line.
Through the following code I am trying to read the TWO input files,
extract columns, Add , Divide (take mean of the values) and write to
THEIR respective OUTPUT files.
My script reads the first file and displays all the rows (print) from
PR1/File1 and then program terminates. IT does not read the Second
file (PR3/File1) and therefore i am unable to write the result out to
the OUTPUT file (PR2/File1).
Earlier I was able to create ONE file ... like the loop would run ONCE
and would not do the same process to the NEXT set of files (PR1/File2
, PR3/File2 , PR2/File2) and do the same.... till it has done
processing all the 96 set of files.
here is the code
PL ... PL .... I REALLY need this solution.
*****************************
import sys, os, fileinput
FileA = raw_input('Enter CSV file with List of Files :')
try:
fp1 = open(FileA,'r')
#print fp1
except IOError:
sys.exit('Could not open File : %s' % FileA)
for rows in fp1:
#print rows
row11 = rows.split(",")
#print row1
row1 = row11[0]
row2 = row11[1]
row3 = row11[2]
#print row1
#print row2
#print row3
try:
fp2 = open(row1,'r')
#print fp2
except IOError:
sys.exit('Could not open File %s.' % fp2)
try:
fp3 = open(row2,'r')
#print fp3
except IOError:
sys.exit('Could not open File %s.' % fp3)
try:
fp4 = open(row3,'w')
#print fp4
except IOError:
sys.exit('Could not open File %s to write.' % fp4)
row21 = fp2.readline().split(",")
row31 = fp3.readline().split(",")
#print row21
row22 = row21[0]
row23 = row21[1]
row24 = row21[2]
row25 = row21[3]
row26 = row21[21]
row27 = row21[22]
row28 = row21[23]
row32 = row31[1]
row33 = row31[2]
row34 = row31[3]
row35 = row31[21]
row36 = row31[22]
row37 = row31[23]
print "PR1", row22, row23, row24, row25, row26, row27, row28,
"PR3", row32, row33, row34, row35, row36, row37
## Doing the Addition is also not the problem. I am not able to put this
## whole process in a loop.
## do the calculation and write to file.
## and do the same thing with the next set of files. Till 96 sets
More information about the Tutor
mailing list