Code: Alles auswählen
from . something
Bei der Doku finde ich keinen sinnvollen Eintrag - wobei er sicherlich existiert. Hab im Index nach "import" gesucht.
Code: Alles auswählen
from . something
Code: Alles auswählen
from . import modul
import modul
# tree
.
|-- sub
| |-- __init__.py
| |-- modc.py
| |-- modd.py
`-- test.py
# cat test.py
from sub import modc
# cat sub/modc.py
import modd
# python3 test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from sub import modc
File "/tmp/test/sub/modc.py", line 1, in <module>
import modd
ImportError: No module named modd
# echo "from . import modd" > sub/modc.py
# python3 test.py
#
Grundsätzlich sollte man allerdings ohnehin ``from __future__ import absolute_import`` nutzen, dann ist auch bei einem ``import spam`` klar was gemeint ist.BlackJack hat geschrieben:@MoonKid: Stell Dir vor es gibt ein systemweites Modul `spam` und eines im Package `parrots`. Und im Packache `parrots` gibt es ein Modul `frob` und das verwendet ein ``import spam``. Welches `spam`-Modul wird da importiert? Bei ``from . import spam`` ist klar welches: das im Package.