How to import a module given its name as string?

前端 未结 11 1396
不思量自难忘°
不思量自难忘° 2020-11-21 06:19

I\'m writing a Python application that takes as a command as an argument, for example:

$ python myapp.py command1

I want the application to

11条回答
  •  抹茶落季
    2020-11-21 07:02

    For example, my module names are like jan_module/feb_module/mar_module.

    month = 'feb'
    exec 'from %s_module import *'%(month)
    

提交回复
热议问题