Unable to import modules in python

I have a filestructure that looks like this:

script.py
plugins
|_ __init__.py
|_ custom
   |_ __init__.py
   |_ test.py

test.py is just a simple test script that looks like this:

def main():
    print('hello world')

within script.py I attempt to import test and run main():

from sys import path
path.append('./plugins/')
from plugins import custom

custom.test.main()

But then I get a lovely AttributeError saying:

AttributeError: module 'plugins.custom' has no attribute 'test'

If I import test by name such as:

from sys import path
path.append('./plugins/')
from plugins.custom import test

test.main()

It works fine, however since I have about 100 modules this isn't really possible. Star imports also do not work and throw a name error:

NameError: name 'test' is not defined

Any help would be appreciated!

LMAY75
Always happy to help, DM me if you need anything!
Link to Profile

Comments

  • You can use from plugins.custom import *. You should make sure to not override built-ins with that, though.


    Hack The Box
    OSWE | GREM | OSCE | GASF | eJPT

    Feel free to PM me your questions, but please explain what you tried, so far.

  • Type your comment> @HomeSen said:

    You can use from plugins.custom import *. You should make sure to not override built-ins with that, though.

    Star imports don't work, I get the name error upon calling test.main()

    LMAY75
    Always happy to help, DM me if you need anything!
    Link to Profile

Sign In to comment.