[Tutor] question about __init__ in a class
shawn bright
nephish at gmail.com
Mon Nov 13 19:44:34 CET 2006
Hello there all.
i have a class that i need to load some class variables depending on what is
passed to the class, it would either be set up using one variable or
another. The values for the class variables would be loaded from a database.
But how it is looked up depends on how its called. Like this:
class Sensor_Object(object):
def __init__(self, id, monitor):
if id:
self.id = id
load values from the database
value1 = somevalue
value2 = someOthervalue
else:
self.monitor = monitor
get some values from database
value1 = somevalue
value2 = someothervalue
now i could call it like this:
new_monitor = sensor.Sensor('', 'XJ191')
or
new_monitor = sensor.Sensor('3433', '')
to load based on the other variable.
i think that this would work, but i was thinking that there must be a
cleaner way to do it.
any suggestions ?
sk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061113/cc34499e/attachment.htm
More information about the Tutor
mailing list