mapping the read() fonction
Bjorn Pettersen
bjorn at roguewave.com
Mon Jul 24 13:52:24 EDT 2000
Benjamin wrote:
>
> I would like to map the read() function of a file object
>
> I have a list of file objects. I want to return the list of their content
> using the map function
>
> I've used the map function to open my list of file
> map(open,list,{"r","r","r"}) (to open a list of 3 files for example)
>
> but I can't do the same for the read() function, because it is a method
> function of the file class
> How can I map the read() fonction to my list of file? The problem is that I
> don't know the class name of a file object.
>
> The only solution for the moment id to use a for loop on my list....
map( lambda f:f.read(), [list of open files])
or perhaps:
def openAndRead(filename):
return open(filename).read()
map( openAndRead, listOfFilenames )
-- bjorn
More information about the Python-list
mailing list