Advertisement
wagner-cipriano

Dynamic Module import in python

Oct 18th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: wagner
  4. Dynamic Module import in python
  5. """
  6. from __future__ import print_function      #Compatibilidade func print python 2/3
  7. import importlib
  8.  
  9. ModList = []
  10. for i in range(2):
  11.     Mod = input('Informe o modulo %s a importar: ' %(i))
  12.     ModList.append(Mod)
  13.  
  14. ExitList = []
  15. for ModName in ModList:
  16.     try:
  17.         Imp = importlib.import_module(ModName)
  18.         ExitList.append('Modulo "%s" importado com sucesso' %(ModName))
  19.     except ImportError as ErrMsg:
  20.         ExitList.append(' Erro ao importar modulo "%s": %s' %(ModName, ErrMsg))
  21.  
  22. print('\n'*2, '\n'.join(ExitList))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement