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

C

chand

Hi.,

In my api.py file 'g_opt_list' is defined globally
g_opt_list =[[],[],[],[],[],[],[]]

when I run the py file, I am getting the Following Error

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

Please let me know how to remove these warnings.

I found that commenting 'g_opt_list' initialisation in "NEW" command
removes this warning message. But my requirement is that i want to
reset g_opt_list to empty list, whenever "NEW" command is called.

Here is the code which gives the error...

I have removed most of the unwanted code to reduce the size.

Let me know exact reason for this warning and how to remove these
warnings..

import os,sys,re,string,math
g_opt_list =[[],[],[],[],[],[],[]]
SIG_STANDARD_HOME = "/home/chandras/SIGNALLING_STANDARD/ANSI_SS7/"
symbols=['(',')','{','}','[',']','.']
reverse_symbols=['<','>','~']
layers=['MTP3','SCCP','IOS','CDTAPM2','CDTAPC2','ISUP','IS-41D-SQA']

GUI_API_COMMAND_LIST = [
"NEW",
"ADD_OPTIONAL_PARAM",
]

Message_obj = Message()
def Process_GUI_Command(arg):
global Message_obj
global filename
out_file = file('/tmp/te.txt', 'w+')

if arg[0] == "NEW" :
global g_opt_list
for i in range(0,len(g_opt_list)):
g_opt_list = []
return layerList

elif arg[0] == "ADD_OPTIONAL_PARAM" :
global g_opt_list
global layers
global index
message_name = ""
add_delete_flag = 0

param_name = optional_parameter_name

g_opt_list[int(index)].append(optional_parameter_name)

def main():

print "####### choice ",

if __name__ == '__main__':
main()
 
F

Fredrik Lundh

chand said:
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>
 
B

Bruno Desthuilliers

chand a écrit :
Hi.,

In my api.py file 'g_opt_list' is defined globally
g_opt_list =[[],[],[],[],[],[],[]]

when I run the py file, I am getting the Following Error

SyntaxWarning: name 'g_opt_list' is used prior to global declaration
SyntaxWarning: name 'layers' is used prior to global declaration
>
Please let me know how to remove these warnings.

By fixing your code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top