Is it possible to call one python script from another Python Script

607    Asked by DylanForsyth in Salesforce , Asked on Apr 16, 2021

I have a script call abc.py in which I have some code. Now i want to run this script by calling it from another script called pqr.py. How to do it in Python?

Answered by Crowny Hasegawa

Yes, it is possible to run another python script.Y ou'll need to import the exact name of the Python script that you'd like to call.

Suppose your script abc.py has the following code.

def my_func():
    print 'I am in abc'
if __name__ == '__main__':
    my_func()

Now you can call this script from another script pqr.py by following code

import abc
def service_func():
    print 'service func'
if __name__ == '__main__':
    service_func()
    abc.my_func()


Your Answer

Interviews

Parent Categories