Python Sockets use function instead of global socket call
<p>Hello I am trying to port some C code to python. I haven't used python in a few months so feel a bit rusty.</p>

<p>Wondering how I can do this. I need to be able to use the send value of the sock object in createConnection function with out making the sock object global.</p>

<p>any ideas?</p>

<p>*cheers</p>

<p>Example code</p>

<pre><code>def createConnection(host, port, tcpTimeout):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
    sock.connect((host, port))
    return sock

def useConnectionOne():
    sock = createConnection("&lt;Some IP&gt;", &lt;Some Port&gt;, 5)
    sock.send("Hello world")

def useConnectionTwo():
    sock = createConnection("&lt;Some IP&gt;", &lt;Some Port&gt;, 5)
    sock.send("Hello again world")
</code></pre>
