Page 1 of 1

open python in python

Posted: Sat Dec 16, 2017 3:32 pm
by louiepi
In python I want to be able to write some code which opens another python file. I want it to open a file instead of the idel. This code opens the idle but if i change idle to python3.5 it doesn't work. How can I get it to work. Looking in the folder idle seems to look like a text file but the python3.5 file looks different. Thanks in advance for any help.

Code: Select all

os.system('/usr/bin/idle3')

Re: open python in python

Posted: Sat Dec 16, 2017 7:56 pm
by DougieLawson
That's not the way to do it.

Look at the python import command and python exec function.

https://docs.python.org/3/reference/import.html
https://docs.python.org/3/library/functions.html#exec

Re: open python in python

Posted: Sat Dec 16, 2017 9:43 pm
by louiepi
DougieLawson wrote:
Sat Dec 16, 2017 7:56 pm
That's not the way to do it.

Look at the python import command and python exec function.

https://docs.python.org/3/reference/import.html
https://docs.python.org/3/library/functions.html#exec
Thanks for the help but I don't understand what to do. Please may you explain it.

Re: open python in python

Posted: Sat Dec 16, 2017 10:36 pm
by DougieLawson
You need to explain what you're trying to achieve, because python's threading may be needed.

Re: open python in python

Posted: Sun Dec 17, 2017 10:48 am
by louiepi
DougieLawson wrote:
Sat Dec 16, 2017 10:36 pm
You need to explain what you're trying to achieve, because python's threading may be needed.
I want to be able to have an empty python document open, so I can then start using it.

Re: open python in python

Posted: Sun Dec 17, 2017 12:22 pm
by DougieLawson
Sorry, I don't have the first faintest clue what you mean by that.

Re: open python in python

Posted: Sun Dec 17, 2017 12:47 pm
by louiepi
Right. I'll try and explain this a bit better, apologies for not being clear before.

I want to write a bit of python code which I will set to start on boot. It will be connected to buttons through the GPIO pins. When I click one of the buttons, I want it to open a new python file, the same thing you get if you click on python and then click new file.

Re: open python in python

Posted: Sun Dec 17, 2017 12:51 pm
by elParaguayo
I'm guessing they just want open IDLE and have it give them a blank document to work in.