I am trying to import a list from a file in python , and i don't know the name of the list or the file .
I am asking them in the code , and when I get them , i am trying to import the list ,
def listIMP(ITEM):
listIMP = "from {0} import {1}".format(ITEM[0],', '.join(str(i) for i in ITEM[1:])) # generating command
exec(listIMP) #exec generated command
I call it :
listN = input('!\n')# asking for list name
name = input('>') # asking for file name
name = name[:-3] #deleting .py
list1 = [name, listN]
listIMP(list1) # calling my func
But i can't get the output , of exec , which is my list , i know i can get it as string but i would like to get it as list , is that possible ?