title: Python - access global list in function
body: <p>I am new to Python, Before this, I was using C.</p>
  
  <pre><code>def cmplist(list): #Actually this function calls from another function
      if (len(list) &gt; 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
  </code></pre>
  
  <p>When I execute this code it shows following error</p>
  
  <pre><code>    if (len(list) &gt; len(globlist)):
  NameError: global name 'globlist' is not defined
  </code></pre>
  
  <p>I want to access and modify globlist from a function without passing it as an argument. In this case output should be</p>
  
  <pre><code>[1, 2, 3, 4]
  </code></pre>
  
  <p>Can anyone help me to find the solution?</p>
  
  <p>Any suggestion and correction are always welcome.
  Thanks in advance.</p>
  
  <p><strong>Edit:</strong>
  Thanks Martijn Pieters for suggestion.
  Origional error is </p>
  
  <pre><code>UnboundLocalError: local variable 'globlist' referenced before assignment
  </code></pre>