[Python-3000] print() parameters in py3k

Barry Warsaw barry at python.org
Mon Nov 20 16:54:51 CET 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 20, 2006, at 9:58 AM, Giovanni Bajo wrote:

> Guido van Rossum wrote:
>
>>> The only thing I would prefer is instead of 'end' have 'newline' and
>>> have that be a boolean since I don't see a need to support different
>>> line endings.  I realize the difference between ``end=''`` and
>>> ``newline=False`` is minimal beyond more typing, but for some reason
>>> my head just keeps telling me I prefer the latter for clarity
>>> reasons.
>>>
>>> Otherwise +1 from me.
>>
>> Oh, but I *do* see a use case for other line endings. E.g. when
>> writing a Windows file or a standards-compliant email from within
>> Unix, end="\r\n" would be helpful. In practice it probably would be a
>> variable set from a config option.
>
> Uhm, but then, why not simply:
>
> println(x,y,z) -> append "\n"
> print(x,y,z) -> no terminator
> print(x,y,z,"\r\n") -> custom terminator

I'd like to at least see a discussion of a more printf() or logging  
style for print function.  Specifically, I wonder if it wouldn't be  
useful to require a format string with positional and keyword  
arguments being used for automatic interpolation.  E.g.

print('%s: %s', field, value)

instead of

print('%s: %s' % (field, value))

There are lots of questions to answer, such as whether to use $- 
strings and require keyword arguments.

Another thought: what if 'print' weren't a function but a callable  
object. exposed in builtins.  I'm thinking something roughly parallel  
to stdout, stderr, stdin, or maybe better cout, cerr, cin.

The default 'print' object then would be a "print-to-sys.stdout-with- 
\n", but you would then be able to do something like:

stderr = print.clone(stream=sys.stderr)
stderr('here go all my error messages')

or

smtpout = print.clone(stream=mysock, end='\r\n')
smtpout('$code $msg', code=250, msg='Okay')

Perhaps you could even hook in i18n by doing something like:

print = print.clone(translate=gettext.gettext)
print('$who likes to eat $what', person, food)

- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRWHP0HEjvBPtnXfVAQJ8HgQAoKfkh94Js4MXMRgjAm3uFHvNxYBrb99k
Je8PkICx1QXhkSH9Kq3KJ3AbWXx/EKQFycfXun9ZxXy/hax7RcsDHJRsR9H1moR7
6IiWBEJJ1IqAjCfTNCKhP4VMxQtq6DFb5rRoN9jfe5pAJeA7SqCM0Fqcdf8F0stG
OWQtK+UIjLU=
=MhoH
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list