Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'from .. import module' mean?

Tags:

python

import

sdl

And I literally mean without replacing the '..'. I have seen this in the PySDL2-0.8.0 library:

from .. import sdlimage

The reason I ask myself this is because I am trying to run one of the examples they provided and reading the traceback leads me to a file that has this:

_HASPIL = True
try:
    from PIL import Image
except ImportError:
    _HASPIL = False

_HASSDLIMAGE = True
try:
    from .. import sdlimage
except ImportError:
    _HASSDLIMAGE = False

And of course at some point in the same file:

if not _HASPIL and not _HASSDLIMAGE:
    raise UnsupportedError(load_image,
                           "cannot use PIL or SDL for image loading")

I do not have PIL (python imaging library) installed, but I do have the sdlimage.py file. So the file I am trying to run is:

/Library/Python/2.7/site-packages/sdl2/examples/helloworld.py

The path to sdlimage.py:

/Library/Python/2.7/site-packages/sdl2/sdlimage.py

And the file that raises UnsupportedError(load_image, "cannot use PIL or SDL for image loading"):

/Library/Python/2.7/site-packages/sdl2/ext/image.py

I think there is something fishy with these imports...Any ideas?

like image 452
skamsie Avatar asked Sep 11 '26 10:09

skamsie


1 Answers

It's a relative import. More on this here: http://docs.python.org/3.3/tutorial/modules.html#intra-package-references

like image 195
1st1 Avatar answered Sep 13 '26 00:09

1st1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!