473,706 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning when doubly linked list is defined gloablly

Hi.,

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

I am using this global list in the fucntion

def function ():
gloabl 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

Please let me know how to remove this error

--BestRegars.,
--Chandra

Aug 24 '05 #1
7 1986

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

I am using this global list in the fucntion

def function ():
gloabl g_opt_list


This is obviously wrong and not the code you wrote, global being
written horribly wrong - which should teach you an important lesson:
post actual code that exposes the problem, not something you think that
is working. Then we might be able to help you.

Diez

Aug 24 '05 #2
chand wrote:
Hi.,

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

I am using this global list in the fucntion

def function ():
gloabl g_opt_list
global?
when I run the py file, I am getting the Following Error

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

Please let me know how to remove this error


This happens in cases like
a = 1
def c():

.... a
.... global a

Does your source only consist of the three lines above? (These would trigger
a SyntaxError because of the typo...)
You should provide a more complete example, so we can tell you where the
problem is. Try to build a minimal file that reproduces the problem. Often
you will find the line causing the error yourself - and the fix might be
obvious to you -, if your strip stuff away.

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Aug 24 '05 #3

"chand" <ch************ ***@gmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi.,

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

I am using this global list in the fucntion

def function ():
gloabl 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

Please let me know how to remove this error


To expand slightly on previous answers:

1. Write a *minimal* file that gives you the error. This means that
removing any statement ceases to give you the error. This may answer your
questions.

2. If still puzzled, post again. But cut and paste that *exact* file and
also the *full* error traceback.

Terry J. Reedy

Aug 24 '05 #4
Hi Terry..,

Here is the code which gives the error...

Let me know exact reason for this Error
import os,sys,re,strin g,math
from xml.dom import minidom, Node
from Layer import Layer
from LMessage import *
from Param import *
from Message import *
from message_mapping import *
from protocol_mappin g import *
from symbol_mapping import *
from opt_list_mappin g import *
g_del_opt_list =[[],[],[],[],[],[],[]]
sflag = 0
index=0
del_index=0
radflag = 0
depth = 0
xmlflag = 0
opt_param_list = []
del_opt_param_l ist = []
#g_opt_list = []
MTAS_HOME="/home/chandras/XML_FILES/"
SIG_STANDARD_HO ME = "/home/chandras/SIGNALLING_STAN DARD/ANSI_SS7/"
symbols=['(',')','{','}' ,'[',']','.']
reverse_symbols =['<','>','~']
layers=['MTP3','SCCP',' IOS','CDTAPM2', 'CDTAPC2','ISUP ','IS-41D-SQA']
GUI_API_COMMAND _LIST = [
"NEW",
"ADD_OPTIONAL_P ARAM",
"DELETE_OPTIONA L_PARAM",
"DELETE_LAY ER",
"RENAME"
]

BASE2 = "01"
BASE10 = "0123456789 "
BASE16 = "0123456789ABCD EF"

Message_obj = Message()
filename =""
buffer = []
#LIST = []
def Process_GUI_Com mand(arg):
global Message_obj
global filename
print "### COMMAND ###", arg[0]
save_fd = os.dup(1)
if arg[0] == "DELETE_OPTIONA L_PARAM":
out_file = file('/tmp/te6.txt', 'w+')
elif arg[0] == "ADD_OPTIONAL_P ARAM":
out_file = file('/tmp/te3.txt', 'w+')
else :
out_file = file('/tmp/te.txt', 'w+')
os.dup2(out_fil e.fileno(), sys.stdout.file no())

if arg[0] == "NEW" :
global g_opt_list
Message_obj = Message()
layerList = listLayers("ANS I_Layers")
layerList = str(layerList)
layerList = layerList.repla ce(",","")
for i in range(0,len(g_o pt_list)):
g_opt_list[i] = []
os.dup2(save_fd , 1)
return layerList
elif arg[0] == "ADD_OPTIONAL_P ARAM" :
global g_opt_list
global layers
global index
message_name = ""
layer_name = arg[1]
#print "Layer Name", layer_name
for layer in layers:
if layer == layer_name:
if OPT_LIST_MAPPIN G.has_key(layer _name):
index = OPT_LIST_MAPPIN G[layer_name]
break

if arg[2] != 'Null':
optional_parame ter_name = str(arg[2]).replace("+"," ,")
for symbol in reverse_symbols :
if symbol in optional_parame ter_name:
if SYMBOL_REVERSE_ MAPPING.has_key (symbol):
old_symbol = SYMBOL_REVERSE_ MAPPING[symbol]
optional_parame ter_name =
optional_parame ter_name.replac e(symbol,old_sy mbol)
Message_obj.Add Param(message_n ame,layer_name,
optional_parame ter_name )
else : optional_parame ter_name= 'Null'
add_delete_flag = 0

param_name = optional_parame ter_name
show_opts(layer _name,add_delet e_flag,param_na me)
if int(add_delete_ flag) == 0:
add_delete_flag = 0
if optional_parame ter_name != "Null":
optList =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,optional_para meter_name)
g_opt_list[int(index)].append(optiona l_parameter_nam e)
for i in g_opt_list[int(index)]:
if g_opt_list[int(index)].count(i) == 1:
optList =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,i)
displayoptparam s(optList,layer _name,0,"Null")
i= "Null"
optional_parame ter_name = "Null"
add_delete_flag = 1
os.dup2(save_fd , 1)

else:
print "Invalid Option"

def show_opts(layer _name,add_delet e_flag,param_na me):
global index
global g_opt_list
#param_name = "Null"
List =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,"Null")
if (len(List)== 0) :
return "None"
displayoptparam s(List,layer_na me,add_delete_f lag,Message_obj ._message_name)
if param_name == 'Null':
for i in g_opt_list[int(index)]:
if g_opt_list[int(index)].count(i) == 1:
optList =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,i)
displayoptparam s(optList,layer _name,0,"Null")
add_delete_flag = 1
return "None"

def main():

#choice = sys.argv[1]
print "####### choice ",
#Process_GUI_Co mmand("NEW")
#list=CMSR.show OptionalParamet ers("SCCP",0)
#CMSR.saveXMLfi le("CMSR2.xml", "CMSR")
if __name__ == '__main__':
main()
--Thanks and bestregards.,
--Chandra

Terry Reedy wrote:
"chand" <ch************ ***@gmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi.,

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

I am using this global list in the fucntion

def function ():
gloabl 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

Please let me know how to remove this error


To expand slightly on previous answers:

1. Write a *minimal* file that gives you the error. This means that
removing any statement ceases to give you the error. This may answer your
questions.

2. If still puzzled, post again. But cut and paste that *exact* file and
also the *full* error traceback.

Terry J. Reedy


Aug 30 '05 #5
Hi All..,
Sorry for mailing the code which does't even compile !!

Please find below the code which compiles. Please let me know how to
resolve this warning message..!!
SyntaxWarning: name 'g_opt_list' is used prior to global declaration
import os,sys,re,strin g,math
from xml.dom import minidom, Node
from Layer import Layer
from LMessage import *
from Param import *
from Message import *
#from message_mapping import *
#from protocol_mappin g import *
#from symbol_mapping import *
#from opt_list_mappin g import *
g_del_opt_list =[[],[],[],[],[],[],[]]
sflag = 0
index=0
del_index=0
radflag = 0
depth = 0
xmlflag = 0
opt_param_list = []
del_opt_param_l ist = []
#g_opt_list = []
MTAS_HOME="/home/chandras/XML_FILES/"
SIG_STANDARD_HO ME = "/home/chandras/SIGNALLING_STAN DARD/ANSI_SS7/"
reverse_symbols =['<','>','~']
layers=['MTP3','SCCP',' IOS','CDTAPM2', 'CDTAPC2','ISUP ','IS-41D-SQA']
GUI_API_COMMAND _LIST = [
"NEW",
"ADD_OPTIONAL_P ARAM",
"DELETE_OPTIONA L_PARAM",
"DELETE_LAY ER",
"RENAME"
]

BASE2 = "01"
BASE10 = "0123456789 "
BASE16 = "0123456789ABCD EF"

Message_obj = Message()
filename =""
buffer = []
#LIST = []
def Process_GUI_Com mand(arg):
global Message_obj
global filename
print "### COMMAND ###", arg[0]
save_fd = os.dup(1)
if arg[0] == "DELETE_OPTIONA L_PARAM":
out_file = file('/tmp/te6.txt', 'w+')
elif arg[0] == "ADD_OPTIONAL_P ARAM":
out_file = file('/tmp/te3.txt', 'w+')
else :
out_file = file('/tmp/te.txt', 'w+')
os.dup2(out_fil e.fileno(), sys.stdout.file no())

if arg[0] == "NEW" :
global g_opt_list
Message_obj = Message()
layerList = listLayers("ANS I_Layers")
layerList = str(layerList)
layerList = layerList.repla ce(",","")
for i in range(0,len(g_o pt_list)):
g_opt_list[i] = []
os.dup2(save_fd , 1)
return layerList

elif arg[0] == "ADD_OPTIONAL_P ARAM" :
global g_opt_list
global layers
global index
message_name = ""
layer_name = arg[1]
#print "Layer Name", layer_name
for layer in layers:
if layer == layer_name:
if
OPT_LIST_MAPPIN G.has_key(layer _name):
index =
OPT_LIST_MAPPIN G[layer_name]
break

if arg[2] != 'Null':
optional_parame ter_name =
str(arg[2]).replace("+"," ,")
for symbol in reverse_symbols :
if symbol in optional_parame ter_name:
if
SYMBOL_REVERSE_ MAPPING.has_key (symbol):
old_symbol =
SYMBOL_REVERSE_ MAPPING[symbol]
optional_parame ter_name
= optional_parame ter_name.replac e(symbol,old_sy mbol)

Message_obj.Add Param(message_n ame,layer_name,
optional_parame ter_name )
else : optional_parame ter_name= 'Null'

add_delete_flag = 0

param_name = optional_parame ter_name
show_opts(layer _name,add_delet e_flag,param_na me)
if int(add_delete_ flag) == 0:
add_delete_flag = 0
if optional_parame ter_name != "Null":
optList =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,optional_para meter_name)

g_opt_list[int(index)].append(optiona l_parameter_nam e)
for i in g_opt_list[int(index)]:
if
g_opt_list[int(index)].count(i) == 1:
optList =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,i)

displayoptparam s(optList,layer _name,0,"Null")
i= "Null"
optional_parame ter_name = "Null"
add_delete_flag = 1
os.dup2(save_fd , 1)

else:
print "Invalid Option"
def show_opts(layer _name,add_delet e_flag,param_na me):
global index
global g_opt_list
#param_name = "Null"
List =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,"Null")
if (len(List)== 0) :
return "None"

displayoptparam s(List,layer_na me,add_delete_f lag,Message_obj ._message_name)
if param_name == 'Null':
for i in g_opt_list[int(index)]:
if g_opt_list[int(index)].count(i) == 1:
optList =
Message_obj.sho wOptionalParame ters(layer_name ,add_delete_fla g,i)

displayoptparam s(optList,layer _name,0,"Null")
add_delete_flag = 1
return "None"

def main():

#choice = sys.argv[1]
print "####### choice ",
#Process_GUI_Co mmand("NEW")
#list=CMSR.show OptionalParamet ers("SCCP",0)
#CMSR.saveXMLfi le("CMSR2.xml", "CMSR")

if __name__ == '__main__':
main()








































































































































































































































































































































chand wrote:
Hi.,

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

I am using this global list in the fucntion

def function ():
gloabl 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

Please let me know how to remove this error

--BestRegars.,
--Chandra


Sep 5 '05 #6
chand wrote:
Sorry for mailing the code which does't even compile !!
You probably missed that other hint where Fredrik Lunddh told you to
somewhat reduce the script's size.
Please find below the code which compiles. Please let me know how to
resolve this warning message..!!
SyntaxWarning: name 'g_opt_list' is used prior to global declaration


This warning occurs if a global variable is used before it is declared as
such:
def f(): .... v = 42
.... global v
....
<stdin>:1: SyntaxWarning: name 'v' is assigned to before global declaration

This kind of code is dangerous because a casual reader might think that v is
a local variable. You can avoid the warning -- and the source of confusion
-- by moving the declaration to before the variable's first usage (I prefer
the top of the function):
def f(): .... global v
.... v = 42
....

In your script things are even more messed up. You declare g_opt_list twice:
def f():

.... global v
.... v = 42
.... global v
....
<stdin>:1: SyntaxWarning: name 'v' is assigned to before global declaration

Now that you understand the cause of the warning it is time to proceed to
yet another effbot hint: You never rebind the global variable g_opt_list
and therefore do not need the

global g_opt_list

statement at all.

Peter

Sep 5 '05 #7

"chand" <ch************ ***@gmail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Please let me know how to
resolve this warning message..!!
SyntaxWarning: name 'g_opt_list' is used prior to global declaration
Post the entire error traceback.
Post the entire error traceback.
Post the entire error traceback ;-).


[hundreds? more snipped]

Don't post hundread of blank lines. It took me at least half a minute to
delete them for this reply.

Terry J. Reedy

Sep 5 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1683
by: chand | last post by:
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 Please let me know how to remove this error
4
2929
by: dssuresh6 | last post by:
Whether browsing forward or backward can be done using a singly linked list. Is there any specific case where a doubly linked list is needed? For people who say that singly linked list allows traversal only in one direction, I would say that using appropriate loops/recursion, traversal in opposite direction is also possible. Then why the need for doubly linked list? --
5
3229
by: free2cric | last post by:
Hi, how to detect head and tail in cyclic doubly link list ? Thanks, Cric
0
1821
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and each node in the list must contain two pointers, one pointing forward and one pointing backwards. Each node in the list will contain 3 data values: an item ID (string), a quantity (integer) and a price (float). The ID will contain only letters and...
2
898
by: murali | last post by:
Hi, I want to insert a node in an sorted doubly linked list of integers in ascending order. The list should not have duplicate nodes. I need an algorithm (assuming an object oriented language) bye
16
1816
by: pauldepstein | last post by:
Can anyone give a realistic example of a task for which the list container works better than vector or deque? Paul Epstein
5
9714
by: adam.kleinbaum | last post by:
Hi there, I'm a novice C programmer working with a series of large (30,000 x 30,000) sparse matrices on a Linux system using the GCC compiler. To represent and store these matrices, I'd like to implement the sparse matrices as a doubly-linked list, in which each non-zero cell is stored roughly as follows: int rownum int colnum
4
3091
kim6987
by: kim6987 | last post by:
can you please spend a little time evaluating this code. I can not run it successfully thanks :) #include<stdio.h> #include<conio.h> #include<stdlib.h> #define SIZE 10 typedef struct dlist
10
1971
by: kalar | last post by:
Hello. we have this struct and we must to make a linked list struct node { char name; char phone; struct node *prevName; // previous node alphabetically struct node *prevNumber; // previous node sorted by numbers struct node *nextName; // next node alphabetically struct node *nextNumber; // next node sorted by numbers } ;
0
8783
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9056
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8999
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7912
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2096
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.