renix1

test using import with list

Dec 28th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. imports = ["sys", "time", "random"]
  2.  
  3. i = 0
  4. while i < len(imports):
  5.     try:
  6.         module = __import__(imports[i])
  7.         globals()[imports[i]] = module
  8.     except NameError:
  9.         print("modules not loaded")
  10.     i += 1
  11.  
  12. def loading(times, msg="Loading modules"):
  13.     sys.stdout.write(msg)
  14.     for i in range(times):
  15.         sys.stdout.write('.')
  16.         sys.stdout.flush()
  17.         time.sleep(int(random.random()*1.9))
  18.  
  19. loading(3)
Advertisement
Add Comment
Please, Sign In to add comment