Python Forum
Python3: problem to import personals modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python3: problem to import personals modules
#1
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!?
Reply
#2
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>
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Different Ways to Import Modules RockBlok 2 461 Dec-11-2023, 04:29 PM
Last Post: deanhystad
  How can prepare the modules when compiling python3.11? luofeiyu 1 522 Sep-28-2023, 03:50 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,257 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  [WORKED AROUND] Problem installing elitech-datareader, 'cannot import build_py_2to3' NeilUK 4 1,561 Jul-09-2023, 10:01 AM
Last Post: NeilUK
  Import Modules TheBunyip 4 1,176 Mar-10-2023, 04:47 PM
Last Post: buran
  a bunch of modules to import Skaperen 2 856 Nov-07-2022, 07:33 PM
Last Post: Gribouillis
  Import requests/beautifulsoup problem Jokadaro_ 3 1,983 Dec-05-2021, 01:22 PM
Last Post: Jokadaro_
  Did interpreter 'compile' all import modules(from thrid-party) jamesyuan 10 4,170 Oct-19-2020, 10:49 AM
Last Post: jamesyuan
  Problem with Flask Bcrypt import module marcello86 2 5,595 Aug-31-2020, 08:10 PM
Last Post: marcello86
  import yaml error for python3 maiya 4 13,019 Jul-15-2020, 06:07 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020