wmsrite
Posts: 5
Joined: Sat Jul 23, 2016 7:08 pm

IDLE executes without f5

Fri Jul 29, 2016 12:13 am

I'm adding a camera to my Pi. Here's the code I'm trying to write in IDLE3

Code: Select all

from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(10)
camera.stop_preview()
However, once i hit enter on

Code: Select all

camera.start_preview()
the IDLE3 editor runs the program and the camera takes over the display. I never get a chance to enter the last 2 lines which would limit the camera preview. I'm not hitting F5, but it's acting like I am. Is this a setting or a bug? Anyone know how to fix this?

wmsrite
Posts: 5
Joined: Sat Jul 23, 2016 7:08 pm

Re: IDLE executes without f5

Fri Jul 29, 2016 12:20 am

I wrote the program in Geany and then opened it in ILDE3 and it worked perfectly. So obviously this is an ILDE issue. Why would it execute the command before the program is finished being written? How can I stop this?

User avatar
Douglas6
Posts: 4860
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: IDLE executes without f5

Fri Jul 29, 2016 12:49 am

IDLE has a REPL (Read-Evaluate-Print Loop). It executes each line as it is entered. You want to use the menu to open a new (or existing) file, which can be executed all at once with F5.

wmsrite
Posts: 5
Joined: Sat Jul 23, 2016 7:08 pm

Re: IDLE executes without f5

Fri Jul 29, 2016 10:49 pm

I thought I was opening a new file. I go to the menu, click on new file, save the file as camera.py and then start writing. Is there a different option for opening a new file?

I'm familiar with REPL's. I use them in Node.js.

How do I open a new file that has the REPL turned off?

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: IDLE executes without f5

Sat Jul 30, 2016 6:02 pm

wmsrite wrote:How do I open a new file that has the REPL turned off?
Start IDLE, and select File -> New File.
This will open a second window.
This second window is a plane text editor where you enter your Python program. You can distinguish it from the Python REPL by the lack of the Python prompt (>>>) at the start of each line.
After you have entered your program, save it, and then run it using the 'F5' function key.

Hope this helps,
Dave.

Return to “Python”