Removing Warning Messages .............

Fredrik Lundh fredrik at pythonware.com
Mon Sep 19 16:47:44 CEST 2005


"chand" <chandra.bangalore at gmail.com> wrote:

> SyntaxWarning: name 'g_opt_list' is used prior to global declaration
> SyntaxWarning: name 'layers' is used prior to global declaration

those messages are preceeded by a line number, which tells you where
to look for the problem.  when I run your snippet, I only get one warning,
which points to the "Process_GUI_Command" function.

from a namespace perspective, that function contains the following
operations on g_opt_list:

    declare g_opt_list as global
    use g_opt_list (in range)
    use g_opt_list (in the list assigment)
    declare g_opt_list as global

the last declaration follows a use (global is a directive, not an ordinary
statement, so the actual program flow doesn't matter here).

> Please let me know how to remove these warnings.

move the global statements to the beginning of the function, and make
sure that you only use it once for each variable.

or get rid of them; from what I can tell, you're only *using* the globals
inside that function.  you only need the "global" directive if you need to
modify the outer scope, not if you're only using stuff from it.

</F> 






More information about the Python-list mailing list