Curios issues with Editors

Robert Boyd robert.h.boyd at gmail.com
Thu Feb 9 08:48:49 EST 2006


On 9 Feb 2006 04:46:21 -0800, rodmc <userprogoogle-139 at yahoo.co.uk> wrote:
> As I said I am most likely to have made an error, being a newbie and
> all that. Here is the offending function. I said i would not post
> source code but there you go...
>
> As I said I plan to change this function, so it will no doubt be out of
> date quite soon.
>
> def senddata(msg):
>     host = "localhost"
>     port = 21568
>     buf = 1024
>     addr = (host,port)
>
>     UDPSock = socket(AF_INET,SOCK_DGRAM)
>     UDPSock.sendto(msg,addr)
>     UDPSock.close()


Are you doing this?
import socket
from socket import AF_INET, SOCK_DGRAM
UDPSock = socket(AF_INET, SOCK_DGRAM)

>>> TypeError: 'module' object is not callable


When you should be calling socket.socket, or from socket import socket.

This code runs in SPE:

from socket import socket, AF_INET, SOCK_DGRAM

host = "localhost"
port = 21568
buf = 1024
addr = (host,port)
msg = 'foo'

UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.sendto(msg,addr)
UDPSock.close()


More information about the Python-list mailing list