Python Forum
Python3: problem to import personals modules - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python3: problem to import personals modules (/thread-8679.html)



Python3: problem to import personals modules - PyForIO - Mar-03-2018

Hi, all.

I have a problem to import personals modules.

My folder:
Quote:test.py
/modules/__init__.py
/modules/config.py
/modules/notification.py

I execute just the script 'test.py', by IDLE, or by run into terminal.
This script call the module 'config.py' without any problem... as:

from modules.config import Config
the 'config.py' need module 'notification.py', and i wrote the code as:
try:
    from modules.notification import Info
except ImportError:
    print(f'Cant import notification module onto Config')
    sys.exit(1)
Result the error:
Error:
Cant import notification module onto Config
I tested with:
from modules import notification
or, by using:
from __future__ import absolute_import

try:
    from . import notification
except ImportError:
or
from .modules import notification
Same problem!

Really, i dont understand!?


RE: Python3: problem to import personals modules - snippsat - Mar-03-2018

my_pack\
|-- test.py
|-- __init__.py
  modules\
  |-- __init__.py
  |-- config.py
  |-- notification.py 
test.py:
from modules.config import Config

print(Config())
config.py:
from my_pack.modules.notification import noti

def Config():
    return 'i am func <Config> in <config.py>'

print(noti())
notification.py:
def noti():
    return 'I am func <noti> in <notification.py>'
Running test.py which will call config.py(Config)--> which will call notification.py(noti).
Output:
C:\Python36\my_pack λ ls __init__.py modules/ test.py C:\Python36\my_pack λ python test.py I am func <noti> in <notification.py> i am func <Config> in <config.py>



RE: Python3: problem to import personals modules - PyForIO - Mar-04-2018

Excuse-me. It's my bad... into notification.py, i have old code python2!

After change pynotify module by notify2 module, it's run correctly...

Really sorry.