title: NameError: global name 'sock' is not defined
body: <p>I've defined a socket called sock in my Main.py. From Main.py I import Functions.py, where there's a function (or a method, dunno how they're called in Python) called sendMessage. In sendMessage I need to use the sock I defined in my Main.py. How do I do this? I've tried adding <code>global sock</code> to my function/method, but to no effect.</p>
  
  <h2>Main.py</h2>
  
  <pre><code>#! /usr/bin/env python
  
  import sys 
  import socket 
  import string 
  import os
  import commands
  import time
  from config import *
  from functies import *
  from php import *
  
  sock = socket.socket ()
  sock.connect ((config['server']['host'], config['server']['poort']))
  
  ...
  </code></pre>
  
  <h2>Functions.py</h2>
  
  <pre><code>#! /usr/bin/env python
  
  def sendMessage (receiver, message):
      global sock
      sock.send ('PRIVMSG ' + ontvanger + ' :' + message + '\n')
  </code></pre>
  
  <h2>The error</h2>
  
  <pre><code>Traceback (most recent call last):
    File "Main.py", line 68, in &lt;module&gt;
      sendMessage (receiver, config['nick'] + ' is here!')
    File "/home/robin/microPy/Functions.py", line 4, in sendMessage
      sock.send ('PRIVMSG ' + receiver + ' :' + message + '\n')
  NameError: global name 'sock' is not defined
  </code></pre>