You seem to be giving a path to a directory rather than a single file. Also you are putting it in the wrong place, you should edit the allFiles list.

Kent

kumar s wrote:
Hi Kent, Thank you for your suggestion. I keep getting
IOError permission denied every time I try the tips
that you provided. I tried to lookup on this error and
did not get reasonable answer. Is this error something
to do with Windows OS?


Any suggestions.

Thank you
K


allColumns = [readColumns("C:\Documents and

Settings\myfiles")for filePath in file_list]

Traceback (most recent call last):
  File "<pyshell#167>", line 1, in -toplevel-
    allColumns = [readColumns("C:\Documents and
Settings\myfiles")for filePath in file_list]
  File "<pyshell#159>", line 2, in readColumns
    rows = [line.split() for line in open(filePath)]
IOError: [Errno 13] Permission denied: 'C:\\Documents
and Settings\\myfiles'




def readColumns(filePath):
    rows = [ line.split() for line in
open(filePath) ]
    return zip(*rows)

# list of all the files to read
allFiles = [ 'f1.txt', 'f2.txt' ]

# both columns from all files
allColumns = [ readColumns(filePath) for filePath in
allFiles ]

# just the second column from all files
allSecondColumns = [ cols[1] for cols in allColumns
]

# a representative first column
col1 = allColumns[0][0]

# zip it up into rows
allRows = zip(col1, *allSecondColumns)

for row in allRows:
    print '\t'.join(row)


Kent



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com



_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Reply via email to