Sign in to follow this  
Storyyeller

python importing woes

Recommended Posts

Storyyeller    215
I am trying to use a Python library which accepts PIL images as input. However, I kept getting strange errors.

Eventually, I discovered that the problem is that I imported PIL using import Image whereas the library imported it with import PIL
and Image and PIL.Image appear to behave differently.

Anyway, I am a beginner to Python so I haven't seen this before. What is the reason for the incompatibility? What can I do to prevent this?

[code]
>>> im = Image.open("twilight.png")
>>> im2 = PIL.Image.open("twilight.png")
>>> isinstance(im, Image.Image)
True
>>> isinstance(im, PIL.Image.Image)
False
>>> isinstance(im2, Image.Image)
False
>>> isinstance(im2, PIL.Image.Image)
True
>>>
[/code]

Edit: On further insepction, it looks like the library isn't even consistent with its type checking. In some places it uses isinstance(im, PIL.Image.Image) and in other places, isinstance(im, Image.Image).
Maybe I should just try to extract the useful bits of the library and strip out all the type checking.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this