namespace question

Alex cut_me_out at hotmail.com
Sat Jun 10 12:26:40 EDT 2000


> If I do the following:
> 
> import socket
> 
> socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
> 
> how do I call a function from the socket module later on?

Well, the best answer might be, "don't do that."  I would call the
socket 'socket_' to prevent the clash.  You could also give the
'socket' module another name, e.g.

import socket
socket_ = socket

socket = socket_.socket_ (blah)

...but I would be inclined to avoid that, as people would expect the
module to be called 'socket', and calling it something else would
proabably confuse them.  It would confuse me for a bit, at any rate.

Alex.



More information about the Python-list mailing list