Easy questions from a python beginner

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Jul 12 19:50:12 EDT 2010


On Mon, 12 Jul 2010 22:57:10 +0200, Alf P. Steinbach /Usenet wrote:

> Existence of a variable means, among other things, that
> 
>    * You can use the value, with guaranteed effect (either unassigned
>    exception
>      or you get a proper value): in particular, you won't be accessing a
>      global if you're using the name of a local declared by a later
>      assignment.

That is too strong. Given the global code:

x

(where x doesn't exist in the global namespace, and therefore does not 
exist, as you agreed earlier) Python promises to raise NameError. By the 
above definition, this counts as "variable x exists".

But surely that is undesirable -- that implies that *all* variables 
exist. Even $%@*@( is a variable that exists, as that is guaranteed to 
raise SyntaxError.



-- 
Steven



More information about the Python-list mailing list