print is not a function
Karl Scalet
news at yebu.de
Thu Oct 9 07:34:56 EDT 2003
Bengt Richter wrote:
> On Wed, 08 Oct 2003 11:32:20 +0200, Karl Scalet <news at yebu.de> wrote:
>
> 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
> Unless you don't like the many calls to sys.stdout.write that are generated
> by that for loop. You can make it into a single write with
>
> sys.stdout.write('\n'.join(my_list+['']))
I like that as well, but as of performance wasn't the issue, the first
solution is easier anyhow.
>
> But if all your pieces already have newlines, or you just want to concatenate strings
> to stdout, note:
Unfortunately the items in the list do not end in newlines,
nevertheless, thanks for pointing out writelines.
But what, if I have a condition on the list.
Everyone tries to keep me away from list-comprehension :-)
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()]
# x having a __str__ in that case :-)
Maybe I do not understand potential problems from side-effects, which
I do not see in *this* case.
Yours insisting-ly,
Karl
More information about the Python-list
mailing list