print is not a function

Michael Chermside mcherm at mcherm.com
Fri Oct 10 09:50:26 EDT 2003


Karl Scalet writes:
> > what's wrong with the straightforward suggestion elsewhere in the thread? 
I.e.,
> > 
> >     for x in my_list: print x
> > 
> 
> I am yet convinced, this is the best solution for printing a simple list
    [...]
> But I do not have a better/easier_to_type solution to
> 
> [sys.stdout.write_whatsoever(x) for x in my_list if x.i_am_good_one()]

Personally, I find

    for x in my_list: print x

to be much easier to read than

    [sys.stdout.write_whatsoever(x) for x in my_list]

And I find
    
    for x in my_list:
        if x.i_am_a_good_one():
            print x

more readable than

    [sys.stdout.write_whatsoever(x) for x in my_list if x.i_am_good_one()]

But hey, that's just me. And most of c.l.py. If YOU find the latter
examples more readable, then go for it! Some folks here have explained
WHY they find the former to be better, but you remain unconvinced...

For myself, I find list comprehensions to be a wonderfully elegant
and readable syntax for describing the creation of a new list. But I
DON'T use it as a syntax for looping... for that I use "for" and "while".
I find it very USEFUL to have different-looking syntax for creating
a list and for (most) other looping. Operations that are different 
should look different... it's the same policy that makes me prefer
Python's syntax to lisp's for most purposes. But that's just my opinion 
on readability, and if you don't agree, then go with your own approach
-- your approach should work fine.

-- Michael Chermside






More information about the Python-list mailing list