So, I am trying to make a program that executes various programs; so say i have P1.py, P2.py and P3.py; I want to execute P1, P2 and P3 in 3 different terminals while still being able to use the main program(The one that opened the 3). How could I do this?
Asked
Active
Viewed 53 times
1
-
Did you intend to tag your question as [openproject]? I've retagged it as [python] unless you want to clarify that it was the right tag. – Aurora0001 Nov 27 '16 at 17:26
-
Please take a look at: http://stackoverflow.com/help/how-to-ask – McNets Nov 27 '16 at 17:59
-
Which platform are you on? You literally want 4 console windows open on your desktop? – tdelaney Nov 27 '16 at 18:27
-
This is very platform dependent.On windows its easy, if you use the `subprocess` module, just add `creationflags = subprocess.CREATE_NEW_CONSOLE` to your call. – tdelaney Nov 27 '16 at 18:35
-
On linux, there are multiple console implementations. I use `gnome-terminal` but `xterm`, `konsole` and many others exist. My environment says `TERM=xterm` but I don't have `xterm` on my system., so it can be hit-and-miss what works. – tdelaney Nov 27 '16 at 18:38
-
I am on ubuntu 16.03 – TAL Nov 28 '16 at 18:02
-
tdelaney, I tried using gnome-terminal on the os module(so it sends the command "gnome-terminal" and then "python P1.py, python P2.py, etc" and "./P1.py, etc" ) but that doesnt seem to work; It does open the terminal though. – TAL Nov 28 '16 at 18:08
-
Thank you mcNets, I will keep that in mind – TAL Nov 28 '16 at 18:10
1 Answers
0
Imagine P1.py contains:
def function1():
print("P1")
if __name__ == '__main__':
function1()
To execute P1.py from P2.py:
import P1
def function2():
print ("P2")
if __name__ == '__main__':
function2()
P1.function1()
If you are using python2 you can simply use this code in P2.py
execfile("P1.py")

Vibhutha Kumarage
- 1,372
- 13
- 26
-
This question might help to you. http://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3-0 – Vibhutha Kumarage Nov 27 '16 at 17:42
-
This isn't running the programs in different windows so I don't see how it helps. – tdelaney Nov 27 '16 at 18:30
-
Vibhutha Kumarage, yeah i know, but i want the program to execute in a different window – TAL Nov 28 '16 at 18:03