[Tutor] "Forward" declarations

Simon Brunning SBrunning@trisystems.co.uk
Fri, 18 Aug 2000 09:06:08 +0100


> From:	Danie Roux [SMTP:s9806673@student.up.ac.za]
> How do I use a variable that is only declared later on in the file? Is
> global what I'm looking for? 
> 
> My question then is does 'global' make the variable global within the
> module or across the whole program?
> 
(Disclaimer - I don't know what I'm talking about.)

I don't think that there is any such thing as 'declaring' a variable in
Python - the first time you assign to a variable, it is created. If you try
to refer to a variable that you have not yet assigned to, you get a name
error.

It doesn't matter *what* might happen further down the module, if you have
not yet assigned to a name, you'll get a name error. (Remember, Python is
interpreted, not compiled. Any code that has not yet been executed is just
so much ASCII text.)

Global makes a variable global within a module, but only once the global
statement has been executed.

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.