using names before they're defined
Rob Williscroft
rtw at freenet.co.uk
Wed Jul 19 13:53:18 EDT 2006
Iain King wrote in news:1153323649.171612.74510
@s13g2000cwa.googlegroups.com in comp.lang.python:
>
> daveho... at f2s.com wrote:
>> [...] 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. [...]
>
> At the top of your code you could put:
>
> supply = None
> compressor = None
> combuster = None
> turbine = None
That doesn't help.
The variable names will be rebound when assigned to the result of
the contructor calls, but only after the previous binding (None) has
been passed to some other objects constructor.
IOW the second line of the OP's code would effectively be:
compressor = Compressor(downstream=None, upstream=supply)
Rob.
--
http://www.victim-prime.dsl.pipex.com/
More information about the Python-list
mailing list