Reputation: 19243
I want to work with Image module in PIL
If I do the following
import PIL
PIL.Image.open()
It says that there is no module named Image.
But the following works fine
from PIL import Image
I am using a package and cant change PIL.Image.open()
how to overcome this problem.
Thanks
Upvotes: 0
Views: 917
Reputation: 308176
Duck typing to the rescue. PIL
doesn't actually have to be a module, it just needs to be an object with the attribute Image
.
>>> from PIL import Image
>>> class MakePIL(object):
def __init__(self, Image):
self.Image = Image
>>> PIL = MakePIL(Image)
>>> PIL.Image
<module 'PIL.Image' from 'C:\Python27\lib\site-packages\PIL\Image.pyc'>
>>> PIL.Image.open(r'c:\temp\temp.jpg')
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=400x250 at 0x2C88D78>
Upvotes: 1
Reputation: 13069
You could try:
from PIL import Image as MyImage
and work with MyImage
Upvotes: 0