[Python-Dev] Optional arguments for str.encode /.decode (original) (raw)
Aahz aahz at pythoncraft.com
Fri Nov 7 10:06:19 EST 2003
- Previous message: [Python-Dev] Optional arguments for str.encode /.decode
- Next message: [Python-Dev] Optional arguments for str.encode /.decode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Nov 07, 2003, Raymond Hettinger wrote:
For example, zlibcodec.py can then express its encoding function as: def zlibencode(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
- Previous message: [Python-Dev] Optional arguments for str.encode /.decode
- Next message: [Python-Dev] Optional arguments for str.encode /.decode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]