print is not a function

Michael Chermside mcherm at mcherm.com
Wed Oct 8 09:15:01 EDT 2003


Karl Scalet writes:
> quite often there is a need to just print out the items of a list.
> 
> [ prt(x) for x in my_list ]
    [...]
> 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.
................................................
> > How about,
> > import sys
> > sys.stdout.write("Hello world!\n")
>
> I came across this, but this requires an extra import sys
> which not always is there, thanks anyhow.


I understand just where you're coming from. My grandmother
was gored to death by a moose named "Fifi", and ever since
I've had a pathological need to avoid "if" statements.
Also, I have a terrible phobia of parallel lines (stemming
from a terrible incident while parallel parking... don't
ask), so I try never to use assignment statements.

I realize that sometimes a straightforward

    if x > 0:
        y = process(x)

or (as in your case)

    for x in my_list:
        print x

is often the clearest and most understandable way to
express an intent, but fortunately, Python's policy of
TASWWODI(*) allows folks like you and I to indulge our
personal programming predilections without regard for
clarity or comprehensibility, allowing instead:

    x > 0 and [y for y in [x]]

or

    [ prt(x) for x in my_list ]


There are those who believe that "for" is the best way
to perform an action on all items in a list, that a 
2-line, 20-character function definition is the most 
obvious way to create a function, that lambdas are the
preferred means for creating annonymous functions (when
you want such a thing), and that import statements are a
nice way to import modules. But these people don't have
to operate under our handicaps.

-- Michael Chermside

(*) TASWWODI: There's Always Some Wierd Way Of Doing It






More information about the Python-list mailing list