Trying to Run PY Files

I have written several codes in a PY files using def… for backtesting of data.

Now I want to use some of such def codes in python(as the need of data and computation be), but I am able run only i def code at a time.



can u help me with a code in python to use multiple def files from a single py file.



Regards



Jigam

 

Hi Jigam,



Thanks for your query.



If I get your query correctly you are looking to run python functions written in a different py file.



For example, let's say that you have a "utiliy.py" file which has following functions



def get_data(ticker):

    # Some code to fetch and return data for a ticker

    pass



def analyze_performance():

    # Some code

    pass






And you have a file say "backtest.py" then you can write below line of code in it to execute the functions stored in utility.py file


Import the function

from utility import get_data


Call the function

data = get_data('SBIN')



You have to make sure that both utility.py and backtest.py are stored in the same folder.



I hope this helps.



Thanks,

Team Quantra