[Python-Dev] Optional arguments for str.encode /.decode
Aahz
aahz at pythoncraft.com
Fri Nov 7 10:06:19 EST 2003
On Fri, Nov 07, 2003, Raymond Hettinger wrote:
>
> For example, zlib_codec.py can then express its encoding function as:
>
> def zlib_encode(input,errors='strict', **kwds):
> assert errors == 'strict'
> if 'level' in kwds:
> output = zlib.compress(input, kwds['level'])
> else:
> output = zlib.compress(input)
> return (output, len(input))
>
> The user can then have access to zlib's optional compression level
> argument:
>
> >>> 'which witch has which witches wristwatch'.encode('zlib', level=9)
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})
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.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
More information about the Python-Dev
mailing list