[Tutor] Assigning function keywords dynamically

Tim Peters tim.one@comcast.net
Mon Jan 6 13:14:22 2003


[Charlie Clark]
> ...
> I know that but I'm more used to dict['item']. I guess it has
> more to with class/functional duality and programming style in Python.
> Could you please explain the difference and the relevance to TOWTDT
> for this.

If you're happy to get a KeyError exception from dict[item], that's fine.
If you would rather raise your own exception if a key is missing, and you
know None isn't a possible dict value,

    result = dict.get(item)  # or dict.get(item, None)
    if result is None;
        raise MyException

is fine.  It's not deep, it's a matter of what you want to do.

>>> <OT>
>>> I remember you once made a remark about it has long been possible to
>>> make real digital computers as opposed to our current binary ones.

>> Sorry, doesn't ring a bell; binary sounds pretty digital to me <wink>.

> Base2 != Base10 the last time I checked.<nudge>

I expect you're conflating "digital" with "decimal", then.  That's unusual.
Digital is usually contrasted with analog, in the sense of discrete versus
continuous.

> It was in connection with floating point and something along the lines
> f "real digital computers have been possible for a long time now and
> would make all of this [floating point] mess unnecessary".

Decimal arithmetic does hold fewer surprises for people than binary
floating-point, not because it's inherently better, but because people have
certain expectations derived from a lifetime of experience with decimal
arithmetic.  That's where the feeling of discomfort comes from when seeing,
e.g.,

>>> .1
0.10000000000000001
>>>

Classes simulating decimal arithmetic in Python are available now; for
example (one close to my heart <wink>)

    http://sourceforge.net/projects/fixedpoint/

Some very early computers did decimal arithmetic in hardware, but direct HW
support for it has been falling ever since.  Here's a good link:

    http://www2.hursley.ibm.com/decimal/