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

0 votes
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?
Jul 2 in Python by Neel
• 1,610 points
16 views

1 answer to this question.

0 votes

Yes it is possible.

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()
answered Jul 2 by Arvind
• 1,530 points

Related Questions In Python

0 votes
1 answer

Is it possible to print all the modules imported in a python script?

Since I am using Python 3.6, I ...READ MORE

answered Jul 3 in Python by Neel
• 1,610 points
15 views
0 votes
1 answer

Is it possible in Python requests to print entire HTTP request?

A better idea is to use the ...READ MORE

answered Nov 26, 2018 in Python by Nymeria
• 3,500 points
40 views
0 votes
1 answer

is it possible to do method overloading in python?

You cannot have two methods with the ...READ MORE

answered Mar 25 in Python by Mohammad
• 1,500 points
23 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 130 views
+4 votes
6 answers
0 votes
1 answer

Is it possible to access .NET code written in C# from Python?

If you want to mainly base your ...READ MORE

answered 2 days ago in Python by Arvind
• 1,530 points
11 views
0 votes
1 answer

is it possible to create zip of a directory in Python?

Please go through this code. This should ...READ MORE

answered Jul 10 in Python by Arvind
• 1,530 points
14 views