I am new to Python, Before this, I was using C.
def cmplist(list): #Actually this function calls from another function
if (len(list) > len(globlist)):
globlist = list[:] #copy all element of list to globlist
# main
globlist = [1, 2, 3]
lst = [1, 2, 3, 4]
cmplist(lst)
print globlist
When I execute this code it shows following error
if (len(list) > len(globlist)):
NameError: global name 'globlist' is not defined
I want to access and modify globlist from a function without passing it as an argument. In this case output should be
[1, 2, 3, 4]
Can anyone help me to find the solution?
Any suggestion and correction are always welcome. Thanks in advance.
Edit: Thanks Martijn Pieters for suggestion. Origional error is
UnboundLocalError: local variable 'globlist' referenced before assignment