How do I know all thrown exceptions of a function?

Steve Williams sandj.williams at gte.net
Tue Jan 23 04:48:20 EST 2001


Fredrik Lundh wrote:

> 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

The Module Documentation Tells You To Use from-import. The most common example
    in this category is Tkinter, which is carefully designed to add only the widget
classes and
    related constants to your current namespace. Using import Tkinter only makes
your
    program harder to read; something that is generally a bad idea.

I parse that to mean 'cruft'.





More information about the Python-list mailing list