using names before they're defined
Diez B. Roggisch
deets at nospam.web.de
Wed Jul 19 11:48:29 EDT 2006
davehowey at f2s.com wrote:
> I have a problem. I'm writing a simulation program with a number of
> mechanical components represented as objects. When I create instances
> of objects, I need to reference (link) each object to the objects
> upstream and downstream of it, i.e.
>
> supply = supply()
> compressor = compressor(downstream=combustor, upstream=supply)
> combuster = combuster(downstream=turbine, upstream=compressor)
> etc.
>
> the problem with this is that I reference 'combustor' before is it
> created. If I swap the 2nd and 3rd lines I get the same problem
> (compressor is referenced before creation).
>
>
> aargh!!! any ideas on getting around this?
the only thing you can do is to either use a name to identify the component
supply = supply('supply')
compressor = compressor(downstream='combustor', upstream='supply')
combuster = combuster(downstream='turbine', upstream='compressor')
or to use some shallow objects that you then fill with information later
supply = supply()
combustor = combustor()
compressor = compressor()
turbine = turbine()
combuster.attach(downstream=turbine' upstream=compressor)
Diez
More information about the Python-list
mailing list