Where and when does Python say this to you?

Chris Rebert clp2 at rebertia.com
Tue Feb 8 08:40:25 EST 2011

On Tue, Feb 8, 2011 at 5:26 AM, gracemia gracemia <gracemia at gmail.com> wrote:
>  File "prueba.py", line 4, in <module>
>    sock = socket(AF_UNIX, SOCK_STREAM)
> NameError: name 'AF_UNIX' is not defined
> code:
> import socket
> sock = socket(AF_UNIX, SOCK_STREAM)

You need to qualify all those names. Normal `import` doesn't dump all
the importee's names into the importer's namespace; it only imports
the name of the module itself. Thus:

import socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

I would recommend (re-)reading the relevant part of the tutorial:

I would also recommend bypassing the EggHeadCafe junk and instead
posting directly to the newsgroup/mailinglist.

More information about the Python-list mailing list