python, trouble with calling functions from a module

后端 未结 2 1318
长发绾君心
长发绾君心 2021-01-29 10:46

I imported a module as below:

filename = \"email\"
mymodule = __import__(\'actions.\'+filename)

the problem I have with this is, that the file

相关标签:
2条回答
  • 2021-01-29 11:15

    The problem is, that you get the actions module returned. Try this:

    mymodule = __import__('actions.'+filename)
    for submodule in filename.split('.'):
        mymodule = getattr(mymodule, submodule)
    

    This happens when you try importing a submodule, i.e. module.something.somethingelse, you get module returned.

    0 讨论(0)
  • 2021-01-29 11:18

    The functions don't exist unless the module executes. You can't have it both ways. Perhaps you need to add a main stanza to the module.

    0 讨论(0)
提交回复
热议问题