gratuitous new features in 2.0

Martijn Faassen m.faassen at vet.uu.nl
Fri Aug 25 18:39:42 EDT 2000


Eric Lorenzo <zo at angband.org> wrote:
> Jeremy Hylton <jeremy at beopen.com> writes:
>> As PEP 214 explains, the print statement has a number of useful
>> features that are not available to a statement like
>> sys.stderr.write(...). 

> The PEP lists these advantages of print:

>     - it auto-converts the items to strings
>     - it inserts spaces between items automatically
>     - it appends a newline unless the statement ends in a comma

> So, basically, it sounds to me like the plan is to complicate core
> language syntax, rather than add a couple of methods to the standard
> file object:

>     def pretty_print(self, *items):
>         self.write(string.join(map(str, items)))

>     def pretty_println(self, *items):
>         self.write(string.join(map(str, items))+'\n')

[snip]

Hm, yeah, at first sight it appears as if a built-in function print
could do just about anything the current print statement can do, 
except the bit with the comma at the end. But of course you can 
do that with introducing a second function. You can accomplish the >>
functionality by making them methods of the file object, too. 
Perhaps the bare functions print() and println() really would be just
references to methods of the stdout object, then. Extremely easy to
override them, too, by just doing an assigment:

print = sys.stderr.print

So, while I don't mind the print statement, is there something else that
makes print special that we're overlooking? Otherwise it would seem to be
smarter just to introduce this system of functions instead. Eventually we
could then even deprecate the statement; Python seems to be dynamic enough
to be able to do without, without losing the flexibility.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list