Cast list of objects to list of strings

bukzor workitharder at gmail.com
Tue Jun 3 01:21:58 CEST 2008


On Jun 2, 2:56 pm, jay graves <jaywgra... at gmail.com> wrote:
> On Jun 2, 4:02 pm, Larry Bates <larry.ba... at websafe.com`> wrote:
>
> > I think what you want is:
> > def write_err(*args):
> >      from sys import stderr
> >      stderr.write("\n".join([str(o) for o in args]))
>
> Slight nitpick.  If you are using version >= 2.4 you could use a
> generator expression instead of a list comprehension to avoid building
> and throwing away a list.
>
> "\n".join(str(o) for o in args)
>
> http://www.python.org/dev/peps/pep-0289/
>
> Very unlikely to yield a material time difference in this case but
> cleaner IMO.
>
> ...
> Jay Graves

Thanks! That's exactly what I was looking for.



More information about the Python-list mailing list