[Tutor] Append function

kumar s ps_python at yahoo.com
Tue Feb 1 22:36:32 CET 2005


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 


More information about the Tutor mailing list