map() question...

Andrew Bennetts andrew-pythonlist at puzzling.org
Sun Jan 12 21:42:53 EST 2003


On Sun, Jan 12, 2003 at 11:50:50PM +0000, Kevin Ethridge wrote:
> Why doesn't map() work with the print function?
> ie map(print, ['Have', 'a', 'great', 'day.'])

Simple -- print isn't a function :)

It's a statement, which is why you can do
    print 'Hi!'
without parens.

This works:

    def prnt(val):
        print val
    
    map(prnt, ['Have', 'a', 'great', 'day.'])

Alternatively, you could use sys.stdout.write as the function.

-Andrew.






More information about the Python-list mailing list