I frequently use this:
def interact():
import code
code.InteractiveConsole(locals=globals()).interact()
Answer from Jason R. Coombs on Stack Overflowinteractive - How to drop into REPL (Read, Eval, Print, Loop) from Python code - Stack Overflow
terminal - How to write a python console application with REPL - Stack Overflow
Noob question: IDE, IDLE, REPL, text editor, Shell, Terminal???
How can I write multi-line code at the Python REPL (in a terminal window)? - Stack Overflow
Videos
I frequently use this:
def interact():
import code
code.InteractiveConsole(locals=globals()).interact()
You could try using the interactive option for python:
python -i program.py
This will execute the code in program.py, then go to the REPL. Anything you define or import in the top level of program.py will be available.
I know this is a noob question but all these terms have me a bit confused. Is anyone able to explain it simply to me? I looked up what an IDE is and I thought that was the python shell? And the IDE and IDLE look similar to each other as well. Any help for a confused noob? lol Thanks in advance
You can add a trailing backslash. For example, if I want to print a 1:
>>> print 1
1
>>> print \
... 1
1
>>>
If you write a \, Python will prompt you with ... (continuation lines) to enter code in the next line, so to say.
To resolve IndentationError: expected an indented block, put the next line after while loop in an indented block (press Tab key).
So, the following works:
>>> i=0
>>> while i < 10:
... i+=1
... print i
...
1
2
3
4
5
6
7
8
9
10
There comes out:
IndentationError: expected an indented block
So, when use the while loop, the next line should have the indented block(press Tab key).
>>> i = 0
>>> while i < 10:
... i += 1
... print i
...
1
2
3
4
5
6
7
8
9
10
>>>