The title may be incorrect. Let's put it in a good way.
We have one main py file. This file allow us to create another py file. And runs the generated file itself. And our main py file saves the value from the file it creates.
a simple example;
#MAIN.py
add_number_list = []
len_add_number_list = int( input( " How many numbers will be in the list? " ) )
for i in range(len_add_number_list):
number = input( " Enter Number = " )
add_number_list.append(number) # We added the number to our list.
file1 = open( "file1.py" , "w" ) # We created a file to run later
code = "" # We create the contens of the file1.py file
file1_variable = [ "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "j" , "k" , "l" ]
code += "def add_list(" # We create function in file1.py
count_variable=0
for i in range(len_add_number_list):
code += file1_variable[ count_variable ]
count_variable += 1
if count_variable == len_add_number_list:
code += " ): \n\t"
break
code += ", "
code += "\treturn "
count_variable=0
for i in range(len_add_number_list):
code += file1_variable[count_variable]
count_variable += 1
if count_variable == len_add_number_list:
break
code += " + "
code += "\nsend = add_list("
count_variable=0
for i in range(len_add_number_list):
code += add_number_list[ count_variable ]
count_variable += 1
if count_variable == len_add_number_list:
code += ")"
break
code += ", "
file1.write(code)
file1.close()
File1.py
#FILE1.py
def add_list(a, b, c, d ):
return a + b + c + d
send=add_list(5,10,11,12)
The above code is an example for you to understand well what I want to say.
Now how can I access the output value from the main.py file after I run the file1.py file in the console?