PEP 214 - Why not print >> string?

Alex Martelli aleax at aleax.it
Fri Jan 11 06:31:38 EST 2002


"Skip Montanaro" <skip at pobox.com> wrote in message
news:mailman.1010702852.21006.python-list at python.org...
    ...
>     Robert> But it makes a lot more sense to use a function which does
>     Robert> exactly the same as print and returns a string:
>
>     Robert> def Print(*args):
>     Robert>    return " ".join([str(x) for x in args])
>
> Well, more Pythonic it may be, but the semantics of two calls to your
Print
> function aren't the same as executing two print statements.  The caller
> would have to insert the required space or newline, depending on whether
the
> print statement she isn't executing has a trailing comma or not.

There's a Cookbook recipe that deals with this issue perfectly well -- in
the version I've edited for the paper version.  The current online version,
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65445 , has some
small issues, but it's still interesting, I believe (I think the online
version of the cookbook will be updated according to the edited one being
published afterwards, but I'm not sure -- Activestate's responsible for
the online version, so it will depend on their plans).


Alex






More information about the Python-list mailing list