gratuitous new features in 2.0

Eric Lorenzo zo at angband.org
Fri Aug 25 12:10:40 EDT 2000


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')

This lets you discourage people from the nasty idiom of setting
sys.stdout to redirect pretty-printing, without touching core syntax.

Eric



More information about the Python-list mailing list