namespace question

David Goodger dgoodger at bigfoot.com
Sat Jun 10 14:23:21 EDT 2000


on 2000-06-10 12:07, Jerome Chan (eviltofu at rocketmail.com) wrote:
> 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?

Answer: Don't do that. Use another name instead.

However, if you insist on doing that, here's the workaround:

>>> import socket
>>> socket
<module 'socket' (built-in)>
>>> socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>>> socket
<socket object, fd=4, family=2, type=1, protocol=0>
>>> import sys
>>> sys.modules['socket']
<module 'socket' (built-in)>
>>> sys.modules['socket'].gethostbyname('www.python.org')
'132.151.1.90'




More information about the Python-list mailing list