How do I run a subprogram from another py file?
hello , i don’ t understand what you want to do exactly but my idea is that you want to call function in another python file:
first : if your subprogram is a function and his name is toto() in totofile.py , you can call it in another file for example in anotherfile.py like this;
from totofile import toto. for more illustration see code if we are saying the samething
totofile.py:
a = 5
b= 7
sum = a + b
print(f"the first sum is a + b and equal to {sum}")
return sum
anotherfile.py:
from totofile import toto #call of fonction , from name_of_file import name_function
def dada():
rest = toto()-5
print(f" after calling the first fonction and subtract 5 to toto() function we have {rest}")
return rest
#the call of function
dada()
##result 7
result:
PS C:\Users\Soldepromopub\Desktop\news> python anotherfile.py
the first sum is a + b and equal to 12
after calling the first fonction and subtract 5 to toto() function we have 7
PS C:\Users\Soldepromopub\Desktop\news>
If it is not what you want let’s see the picture of your problem!
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.