Lithy
Lithy

Reputation: 877

Import submodule from another one

I though it was easy, but I just can't do it. I read in the doc that this should work :

File a/__init__.py

 #nothing here

File a/b.py

var = "hello world"

File a/c.py

import b
print(b.var)

From . :

>>> import a.c
ImportError: No module named 'b'

But it does not… What have I forgotten ? Is it because I use Python 3 ?

Upvotes: 0

Views: 447

Answers (2)

monitorius
monitorius

Reputation: 4006

yes, it's because of Python3.

In Python 3, implicit relative imports within packages are no longer available

Changes in import statement python3

Upvotes: 1

Ravenclaw968
Ravenclaw968

Reputation: 1

Never mind that, I believe you should save your file in Program Files (x86)/Lib to create a new module, well that is for Python 2.7.6, but it is very possible it will work too for Python 3.0.

Upvotes: 0

Related Questions