Sono la seguente struttura del codice sorgentePython package import dalla directory padre
/testapp/
/testapp/__init__.py
/testapp/testmsg.py
/testapp/sub/
/testapp/sub/__init__.py
/testapp/sub/testprinter.py
dove testmsg
definisce la seguente costante:
MSG = "Test message"
e sub/testprinter.py
:
import testmsg
print("The message is: {0}".format(testmsg.MSG))
Ma io sto ottenendo ImportError: No module named testmsg
Non dovrebbe funzionare dopo la struttura del pacchetto? Non voglio davvero estendere sys.path in ogni sottomodulo e non voglio nemmeno usare l'importazione relativa.
Cosa sto facendo di sbagliato qui?
Come si esegue il codice? –
@SimeonVisser che esegue 'python sub/testprinter.py', ma anche' python testprinter.py' nella directory 'sub' non funziona. –