0

The below code works great to print out what i am trying to do:

#!/usr/bin/env python3
MODULES = [
['termcolor','colored','cprint'],
['signal','signal','SIGINT'],
['some_other_mod','one','two','three','four','five','six','seven','eight']
]

for ITEM in MODULES:
        print("from",'{0} import {1}'.format(ITEM[0],', '.join(str(i) for i in ITEM[1:]))))

When I run the script, it's printed nicely, but unsure how to make it actually do it.

$ ./script.py
from termcolor import colored, cprint
from signal import signal, SIGINT
from some_other_mod import one, two, three, four, five, six, seven, eight

Using exec() with printed format doesn't seem to work. You can see what I am trying to do. If I can list/loop through to import the modules, it would be great.

parsecpython
  • 585
  • 2
  • 6
  • 17

0 Answers0