converting from perl: variable sized unpack
iron at mso.oz.net
Tue Jul 17 18:20:39 EDT 2001
phil hunt <philh at comuno.freeserve.co.uk> wrote:
> However, im my experience, most of the time you don't want to do this,
> most of the time, if there are too few or many values, you weant the
> software to "do its best".
Perl "does its best" by making guesses about what you want. Python is
more deterministic, which means you have a greater certainty about what
the program will actually do.
> This goes for lots of things; IMO if you
> access a list or dictionary with a non-existant index it should
> return a value such as None, instead of raising an exception.
Sometimes. It's convenient in CGI to have tags default to '' if missing.
But you can't find a one-size-fits all solution. For some applications,
None and '' are legitimate values, and must be distinguished from
"key not found". Thus, why Python offers both dict.get('x', DEFAULT)
as well as dict['better be there or KeyError'].
-Mike (Iron) Orr, iron at mso.oz.net (if mail problems: mso at jimpick.com)
http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol
More information about the Python-list