[Python-Dev] Optional arguments for str.encode /.decode
Barry Warsaw
barry at python.org
Fri Nov 7 10:14:54 EST 2003
On Fri, 2003-11-07 at 10:06, Aahz wrote:
> Change this to
>
> def zlib_encode(input,errors='strict', opts=None):
> if opts:
> if 'level' in opts:
> ...
>
> >>> 'which witch has which witches wristwatch'.encode('zlib', {'level':9})
Actually, I like that less. It looks gross to me. Keyword arguments
are a bit nicer, but do open the possibility for interference with
future arguments to .encode() and .decode(). I'm probably +0 with the
original and -0 with this style.
> and I'm +1. Otherwise I'm somewhere around -0; I agree with Barry about
> possible pollution. This change is a small inconvenience for greater
> decoupling. opts could be an instance instead, but I think a straight
> dict probably makes the most sense.
Actually what I was complaining about probably is too late to "fix". It
was the use of a string for the first argument to .encode() and
.decode(). I dislike that for the same reason we don't do
obj.__dict__['attribute'] on a regular basis. ;)
-Barry
More information about the Python-Dev
mailing list