Reputation: 75
I wrote a piece of code called quadForm.py that solves a quadratic formula. I am trying to place that code into another file where it will output the values. I am new to python and not sure on how to do this. Thanks for the help!
Upvotes: 0
Views: 129
Reputation: 237
You may use the python import
statement. Let us assume you are using a function solve()
defined in quadForm.py in another file main.py in the same directory. Then in main.py you would write the following
import quadForm
quadForm.solve()
or if you want to call the function solve
directly without using the quadForm
prefix
from quadForm import solve
solve()
Upvotes: 1
Reputation: 3277
All you need to do is put the the files in the same directory and add,
from quadForm import *
to the other file. Then you can use any function that you defined in quadForm.py (using def) in the other file.
Upvotes: 0