Re: Identifying exceptions

Chris Hoffmann (choffman@dvcorp.com)
Tue, 7 Mar 95 11:57:50 EST

Guido van Rossum writes:
> > > Are there other, better solutions?
> > D) If you really can't stand using module identifiers all the time
> >
> > import socket
> > import struct
> > from socket import *
> > from struct import *
> >
> > Now you can use either unqualified or qualified names, as you see fit.
>
> Oops! the socket module defines a function 'socket', so the statement
> "from socket import *" redefines the name socket, and "socket.error"
> won't work :-(
>
> --Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
> <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>

Exactly right. As soon as I saw my own posting I realized that the
order should be:

from socket import *
from struct import *
import socket, struct

Which just further goes to show you the dangers of the "import *"
mechanism. Without the qualifiers its very easy to get confused about
where a symbol came from and end up using the wrong one.

Chris

-- 
Chris Hoffmann				DataViews Corporation
choffman@dvcorp.com			47 Pleasant St. Northampton MA 01060
GCS d H s+: g+ ?p a w v+ C+$ US+ P++(++++) L E+(+++) N++ K W--->-- M+
V- po- Y+ t+ 5+(+++) Jx R G tv b+++ D+ B-() e+++ u++ h---- f r+++ n--- y++++