By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

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

P: n/a
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[i] = []
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()

Sep 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"chand" <ch***************@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>

Sep 19 '05 #2

P: n/a
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
Sep 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.