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
  'import requests' problem Curbie 2 754 Aug-14-2024, 01:04 AM
Last Post: Curbie
Bug Python 3.12 cannot import local python files as modules sunflowerdog 25 17,273 Jul-31-2024, 01:52 PM
Last Post: sunflowerdog
  Different Ways to Import Modules RockBlok 2 1,346 Dec-11-2023, 04:29 PM
Last Post: deanhystad
  How can prepare the modules when compiling python3.11? luofeiyu 1 2,115 Sep-28-2023, 03:50 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 9,371 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  [WORKED AROUND] Problem installing elitech-datareader, 'cannot import build_py_2to3' NeilUK 4 4,187 Jul-09-2023, 10:01 AM
Last Post: NeilUK
  Import Modules TheBunyip 4 2,206 Mar-10-2023, 04:47 PM
Last Post: buran
  a bunch of modules to import Skaperen 2 1,530 Nov-07-2022, 07:33 PM
Last Post: Gribouillis
  Import requests/beautifulsoup problem Jokadaro_ 3 3,072 Dec-05-2021, 01:22 PM
Last Post: Jokadaro_
  Did interpreter 'compile' all import modules(from thrid-party) jamesyuan 10 6,662 Oct-19-2020, 10:49 AM
Last Post: jamesyuan

Forum Jump:

User Panel Messages

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