python, trouble with calling functions from a module

后端 未结 2 1317
长发绾君心
长发绾君心 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.

提交回复
热议问题