FAQ
Hello !

I'm trying to develop with AF_UNIX socket type in python (2.5) but
python says that AF_UNIX is not supported
How can I do for work with AF_UNIX sockets?

Thank you

Search Discussions

  • Jean-Paul Calderone at Feb 8, 2011 at 12:49 pm

    On Feb 8, 7:30?am, gracemia wrote:
    Hello !

    I'm trying to develop with AF_UNIX socket type in python (2.5) but
    python says that AF_UNIX is not supported
    How can I do for work with AF_UNIX sockets?

    Thank you
    Where and when does Python say this to you?

    http://docs.python.org/library/socket.html#socket.AF_UNIX

    Jean-Paul
  • Gracemia gracemia at Feb 8, 2011 at 1:26 pm
    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)

    Thank you !


    Submitted via EggHeadCafe
    Statistics, Probability, Lotteries and Dumb Programmers
    http://www.eggheadcafe.com/tutorials/aspnet/041de19a-e704-468f-bd3c-79164fc739f5/statistics-probability-lotteries-and-dumb-programmers.aspx
  • Peter Otten at Feb 8, 2011 at 1:38 pm

    gracemia gracemia 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 the variable names with the module name:

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

    Have you worked through the tutorial

    http://docs.python.org/tutorial/index.html

    already?
  • Terry Reedy at Feb 8, 2011 at 6:25 pm

    On 2/8/2011 8:38 AM, Peter Otten wrote:

    import socket
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    If you do not like typing 'socket' so many times:

    import socket as so # or pick own abbreviation
    sock = so.socket(so.AF_UNIX, sot.SOCK_STREAM)
    Have you worked through the tutorial

    http://docs.python.org/tutorial/index.html
    It is worth reading through more than once.

    --
    Terry Jan Reedy
  • Chris Rebert at Feb 8, 2011 at 1:40 pm

    On Tue, Feb 8, 2011 at 5:26 AM, gracemia gracemia 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:
    http://docs.python.org/tutorial/modules.html

    Cheers,
    Chris
    --
    I would also recommend bypassing the EggHeadCafe junk and instead
    posting directly to the newsgroup/mailinglist.
    http://blog.rebertia.com
  • Gracemia at Feb 8, 2011 at 2:08 pm

    On 8 feb, 14:40, Chris Rebert wrote:
    On Tue, Feb 8, 2011 at 5:26 AM, gracemia gracemia 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:http://docs.python.org/tutorial/modules.html

    Cheers,
    Chris
    --
    I would also recommend bypassing the EggHeadCafe junk and instead
    posting directly to the newsgroup/mailinglist.http://blog.rebertia.com
    Sorry about my reply numbers, my browser blocked.

    Thank you very much. It works for me.
  • Grant Edwards at Feb 8, 2011 at 2:54 pm

    On 2011-02-08, Chris Rebert wrote:
    On Tue, Feb 8, 2011 at 5:26 AM, gracemia gracemia 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;
    Unfortunately, it's somewhat common for example code in various places
    to show the above usage (where somebody did a "from <whatever> import
    *). IIRC there used to be examples like that even in the official
    docs, but I haven't seen any there in a while.

    But examples that look like that are still pretty easy to stumble
    across using Google.

    I'm guessing he copied the code from a "tutorial" example like this:

    http://www.evolt.org/node/60276

    --
    Grant Edwards grant.b.edwards Yow! hubub, hubub, HUBUB,
    at hubub, hubub, hubub, HUBUB,
    gmail.com hubub, hubub, hubub.
  • Gracemia gracemia at Feb 8, 2011 at 1:27 pm
    This is the simple code:

    ----------------------------------------
    import socket

    sock = socket(AF_UNIX, SOCK_STREAM)
    ------------------------------------------

    Thank you

    Submitted via EggHeadCafe
    SQL Server CLR Stored Procedures for External Access
    http://www.eggheadcafe.com/tutorials/aspnet/08c40d08-af4a-41f6-9352-91ac82b90078/sql-server-clr-stored-procedures-for-external-access.aspx
  • Benjamin Kaplan at Feb 8, 2011 at 1:39 pm

    On Tue, Feb 8, 2011 at 8:27 AM, gracemia gracemia wrote:
    This is the simple code:

    ----------------------------------------
    import socket

    sock = socket(AF_UNIX, SOCK_STREAM)
    ------------------------------------------

    Thank you
    I think you're having a bit of trouble with Python's namespaces. doing
    "import socket" does not give you all of the socket module's stuff in
    your current namespace. For that, you do "from socket import *", but
    that's bad form because you can end up clobbering a lot of stuff.
    There's two ways to do it:


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

    from socket import socket, AF_UNIX, SOCK_STREAM
    sock = socket(AF_UNIX, SOCK_STREAM)
  • Gracemia gracemia at Feb 8, 2011 at 1:28 pm
    this is the simple code:

    --------------------------------------------------
    import socket

    # Create an unbound and not-connected socket.
    sock = socket(AF_UNIX, SOCK_STREAM)

    ---------------------------------------------------

    Thank you !

    Submitted via EggHeadCafe
    SharePoint Tip / Thought of the Day WebPart
    http://www.eggheadcafe.com/tutorials/aspnet/14280ff8-3c9f-46bd-8214-9267e613c8ec/sharepoint-tip--thought-of-the-day-webpart.aspx

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 8, '11 at 12:30p
activeFeb 8, '11 at 6:25p
posts11
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase