PEP 259: Revise to remove context-driven magic from print

Remco Gerlich scarblac at pino.selwerd.nl
Fri Jun 15 02:28:55 EDT 2001


Alex Martelli <aleaxit at yahoo.com> wrote in comp.lang.python:
> "David LeBlanc" <whisper at oz.nospamnet> wrote in message
> news:9gamor$8ft$6 at 216.39.170.247...
>     ...
> > makes sense to me. I also liked someone's idea of __print__ - if that
> 
> The 'someone' was me ("was I"...?).
> 
> > idea was in respect of giving objects the power to (as it where) print
> > themselves (return their string representation - so call it asstring()).
> 
> How would that differ from the existing __str__ and __repr__ methods?
> 
> No, __print__ would rather underlie the print statement just like
> __import__ underlies the import (and from) statements.  But I guess
> I gotta write a PEP about it...

I'm missing the point, I think. What would be useful about that function?

I suppose you could override it if you wanted to change print's behavior
by assigning to __builtin__.__print__ or so, but then you have a global
magic function! And if you override it locally, I don't see how print would
use it. Overriding the way print works globally sounds like Perl to me.

__import__ is useful if you want to do call it with a string, or do
something with it other than assign it to a name in the local namespace. But
I don't see any equivalent things with __print__.

-- 
Remco Gerlich



More information about the Python-list mailing list