I'm doing some image processing and have the need to import two modules, but those modules have same class name. Example:
from wand.image import Image
from PIL import Image
The method(s) I'm using, unfortunately, are not contained in both, hence my need for the two modules. Currently my workaround to this problem is import the modules over and over again in a for loop, but this seems incorrect. Example:
for my_images in images:
from wand.image import Image
# run code for this module
from PIL import Image
# run code for this module
Is there a way I can 'rename' or call the class/method using a different name? Thanks.
You can use, for example:
from wand.image import Image as Image_wand
from PIL import Image as Image_PIL
or any another different names with a help of as
.
As others have said you could use as
.
Another possibility is importing the modules, then referencing the classes from there.
import wand
import PIL
wand.image.Image()
PIL.Image()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With