using names before they're defined
davehowey at f2s.com
davehowey at f2s.com
Thu Jul 20 15:19:22 EDT 2006
Hiya
Could you just talk me through this... is it:
> schema = {'turbine1': {'class': 'Turbine',
> 'upstream' : ('frobnicator2',),
> 'downstream' : () # nothing,
> },
> 'frobnicator2' : {'class' : 'Frobnicator',
> 'upstream' : (),
> 'downstream' : ('frobnicator2',),
> },
> }
>
ok, so schema is a dictionary of different components, defining what
class they are and what they're connected to.
> def get_class_by_name(name):
> return globals()[name]
what does this function do exactly?
> def chain_from_schema(schema):
> objects = {} # so objects is our list of objects ?
> for name, desc in schema: # can you step through a dictionary like this?
> klass = get_class_by_name(desc['class']) # does this create an object called klass?
> objects[name] = klass()
sorry for being dim..
Dave
More information about the Python-list
mailing list