print is not a function

Gonçalo Rodrigues op73418 at mail.telepac.pt
Wed Oct 8 06:19:11 EDT 2003


On Wed, 08 Oct 2003 11:32:20 +0200, Karl Scalet <news at yebu.de> wrote:

>Hi,
>
>quite often there is a need to just print out the items of a list.
>
>[ prt(x) for x in my_list ]
>
>that would be nice, except prt() does not exist, and print is a
>statement not a function, hence cannot replace prt as of above.
>
>I don't like to write d
>def prt(x):
>     print x
>beforehand and any lambda construct would not be so handy.
>It should be a short one-liner.
>Any ideas?
>
>Karl

How about,

>>> import sys
>>> sys.stdout.write("Hello world!\n")
Hello world!
>>> 

>>> help(sys)
[text snipped]
    stdin -- standard input file object; used by raw_input() and
input()
    stdout -- standard output file object; used by the print statement
    stderr -- standard error object; used for error messages
      By assigning other file objects (or objects that behave like
files)
      to these, it is possible to redirect all of the interpreter's
I/O.
[text continues]

Hope it helps, with my best regards,
G. Rodrigues




More information about the Python-list mailing list