generic class for everything?
Rob Brown-Bayliss
rob at zoism.org
Sat Mar 29 15:44:43 EST 2003
> (sorry for replying directly, but it seems that the news server of my
> provider has some problem today... Would you please forward this message
> to clp ?)
>
> Using a single large string may be the worth solution here (IMHO). I
> would not appreciate having to debug such a code !-)
>
> One solution might be using a list of strings (or anything else you
> need). This is usually cleaner and faster than concatening and parsing
> strings.
>
> Another solution could be to dynamically append attributes to the instance.
>
> Now reading your 'big string', it appears that your 'events' are all
> composed of two values : what part of the car is affected, and how it is
> affected. So it's something like a key/value pair.
>
> Have you considered using a dictionnary :
> events = {"fule": 0,
> "fule_light": 1,
> "power_out" : -100,
> "electrical_out" : -100,
> "lights : 0}
>
> where each key might also be the name of an attribute in the 'car' class
>
> Now you can iterate on the key/value pair to set the attributes of the
> car instance :
Yes I had thought that, How can I automatically treat the "key" as a
function or variable?
Rather than do the eqivalant of "if somedict has key "x" then
function_x(somedict[x])" i would rather do something like:
for key in somedict: key(value)
But am not sure how to get there?
--
* Rob Brown-Bayliss
* =================
* zoism.org
More information about the Python-list
mailing list