PIL Open Problem

Richard Holmes richardh at dslextreme.com
Tue Feb 8 01:43:50 CET 2011

On Tue, 08 Feb 2011 10:56:52 +1100, Ben Finney
<ben+python at benfinney.id.au> wrote:

>Richard Holmes <richardh at dslextreme.com> writes:
>> Thanks, Ben. It turns out that I imported both Image and Tkinter and
>> Tkinter has an Image class that masked the Image class in the Image
>> module. I solved the problem by moving the Image code to a separate
>> module
>This is a classic problem known as “namespace clobbering”.
>It is best to *avoid* the recommendations made in many libraries of
>‘from foo import *’, because that will clobber any names in your
>namespace that happen to match names in the ‘foo’ module.
>Rather, import Tkinter and PIL as distinct namespaces::
>    >>> import PIL.Image
>    >>> import Tkinter as tk
>    >>> tk.Image
>    <class Tkinter.Image at 0xf6d7f3c0>
>    >>> PIL.Image
>    <module 'PIL.Image' from
>    >>> '/usr/lib/python2.6/dist-packages/PIL/Image.pyc'>
>and then you know that none of the names from those modules will clobber
>existing ones.

Thanks. Message understood.

More information about the Python-list mailing list