How do I know all thrown exceptions of a function?

Fredrik Lundh fredrik at effbot.org
Tue Jan 23 02:45:18 EST 2001


Steve Williams wrote
> > you should use
> >
> >      import somelib
>
> Well, yes.  But that brings in all the other cruft in somelib, when we just
> wanted somefunc.

No, it doesn't.  "import" is not the same thing as C's "include"
statement.  The above statement brings in "somelib", and no-
thing else.

I think you need to read up on how imports work, before
proceeding.

Start here:

    http://effbot.org/guides/import-confusion.htm

and then read the relevant portions of the standard docs.

> We could also use
>
>     from somelib import *

As long as we're talking imports, that's about as far from
"import somelib" as anything can get.

> Now we are getting dangerously close to saying something like "don't ever use
>
>     from somelib import somefunc
>
> because we don't know the exceptions or how the exceptions are defined."

No, the rule is "don't ever use from-import if you don't know what
you're doing".

Cheers /F





More information about the Python-list mailing list