[Tutor] What does import really do?

Kent Johnson kent37 at tds.net
Wed Aug 16 03:32:19 CEST 2006

jim stockford wrote:
> many thanks.
>     wrt import and what's named, in the case of
> the PIL library, the import statement can be
> import Image # not import PIL
That is because the directory Lib/site-packages/PIL is in sys.path, so 
any PIL module can be imported directly without the PIL prefix. (The PIL 
dir is added to sys.path by the file Lib/site-customize/PIL.pth.)

>     my presumption is that the PIL whatever-it-is
> contains a set of whatever-they-are, one of
> which is named Image.
In the above usage I would say PIL is a directory containing a 
collection of modules. But PIL is also a package, since you can say
  from PIL import Image


More information about the Tutor mailing list