louiepi
Posts: 112
Joined: Mon Mar 13, 2017 6:54 pm

open python in python

Sat Dec 16, 2017 3:32 pm

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')

User avatar
DougieLawson
Posts: 36540
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: open python in python

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
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

louiepi
Posts: 112
Joined: Mon Mar 13, 2017 6:54 pm

Re: open python in python

Sat Dec 16, 2017 9:43 pm

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.

User avatar
DougieLawson
Posts: 36540
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: open python in python

Sat Dec 16, 2017 10:36 pm

You need to explain what you're trying to achieve, because python's threading may be needed.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

louiepi
Posts: 112
Joined: Mon Mar 13, 2017 6:54 pm

Re: open python in python

Sun Dec 17, 2017 10:48 am

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.

User avatar
DougieLawson
Posts: 36540
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: open python in python

Sun Dec 17, 2017 12:22 pm

Sorry, I don't have the first faintest clue what you mean by that.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

louiepi
Posts: 112
Joined: Mon Mar 13, 2017 6:54 pm

Re: open python in python

Sun Dec 17, 2017 12:47 pm

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.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: open python in python

Sun Dec 17, 2017 12:51 pm

I'm guessing they just want open IDLE and have it give them a blank document to work in.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Return to “Python”