restricting import to current package

Jeff Kunce kuncej at mail.conservation.state.mo.us
Fri Oct 6 10:40:08 EDT 2000


> >Is there a way to do something like:
> >   from . import mymodule
> >In other words:
> >  try to import mymodule from the same package (or directory) as this
module
> >  If mymodule is not there, raise ImportError
> >
> import mymodule
> see the tutorial on intrapackage references

Not really. That will look *first* in the current package, but then will
go merrily down sys.path looking for any other mymodule it can find.

When you say:
      from mypackage import mymodule
python will look for mymodule *exclusively* in mypackage.
I want to do the same thing for the (unspecified) current package.

  --Jeff







More information about the Python-list mailing list