[Tutor] Assigning function keywords dynamically

Charlie Clark charlie@begeistert.org
Mon Jan 6 12:25:36 2003


On 2003-01-06 at 00:34:40 [+0100], Tim Peters wrote:
> You're building a mapping from strings to durations, which screams 
> "dict". Like so:
> 
> _name2dur =3D {"monatlich": RelativeDateTime(months=3D+1),
>              "w=F6chentlich": RelativeDateTime(weeks=3D+1).
>              "t=E4glich": RelativeDateTime(days=3D+1),
>             }
>dur =3D _name2dur.get(interval)

mm, okay I understand the mapping thing but this doesn't seem much more 
efficient (in terms of typing) or sensible than the series of ifs I had; it=
 
probably runs a lot faster though but then again that isn't important when 
compared with the subsequent SQL calls... But the mapping should be 
{"monatlich": "months"...} with an intermediary function (lambda()?, 
exec()?) magically inserting the keyword in a RelativeDateTime() call.

ie. return now() + RelativeDateTime(magicfunction(dur))

I also have three questions: why do you use the "_" in the name? And is 
.get() becoming standard for dictionaries? how close is the upcoming 
"datetime" module to mx.DateTime. For those not already aware Python 2.3 
will ship with a new datetime module which has many functions similar to 
the very useful eGenix's mx.DateTime.

<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. Could you 
provide a reference? I discuss these kind of things with my dad who while 
regularly presenting a replica of the world's first electronic computer 
("Baby" at the Museum of Science and Industry in Manchester) and going back=
 
as far as IBM 704s, etc. doesn't seem to recall such devices. They sound 
fascinating and probably very useful.

<really off-topic and possibly bear-baiting>
Can anybody point me to a reasonable reference as to why so much time, 
energy has been spent "developing" Linux over the last 10 years in order to=
 
come up essentially with a new 4.4 BSD lite? My real interest in this is: 
why did yet another Unix clone receive such tremendous input from the 
academic community although it seemed essentially to be reinventing the 
wheel and repeating the mistakes and lessons of the previous 20 years. As 
only an occasional programmer what interests me primarily are the "design" 
and "project management" issues which are common to all open source 
projects. The relation to Python is that Python seems to have maintained 
focus and avoided feature creep to a large extent while managing to be 
innovative I understand and increasingly respect this but it leaves me 
wondering: how much innovation occurs when the commercial imperative is 
removed? Apply this directly to Python: how many modules which are now part=
 
of the standard library were themselves previously commercial extensions or=
 
are clean room implementations of such modules, ie. mx.DateTime and 
datetime; when can we afford to give something away?
</really off-topic and possibly bear-baiting>

</ot>

Thank you very much
Charlie