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
• 3,010 points
38 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
• 2,960 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
• 3,010 points
29 views
0 votes
1 answer

Is it possible to launch python idle from a virtual environment?

Assuming that you are using python 3, ...READ MORE

answered Aug 8 in Python by Neel
• 3,010 points
21 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,520 points
66 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 232 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 Jul 18 in Python by Arvind
• 2,960 points
23 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
• 2,960 points
21 views