-1

How would you make the IDLE shell, using nothing but Python code? Now, I understand the beggingins, like a simple exec(raw_input('>> ')), but how would you get if and else statments, or for and while loops to work?

while 1==1:

is considered invalid syntax. How would you prevent that?

The suggested thread isn't nearly the same thing, as all of the answers but one answer how to run a python program from a python program. One of the answers points kinda of like what I'm asking, but it would still fail in an if and else statement, or a while or for loop.

  • What do you mean, `while 1==1:` is invalid syntax? It's perfectly fine. Did you forget to put in a loop body when you tried it out? – user2357112 Apr 01 '16 at 02:00
  • If I had to make the IDLE shell in Python it would probably look something like this https://github.com/python/cpython/tree/master/Lib/idlelib – Ry- Apr 01 '16 at 02:03
  • @user2357112 I mean that if my code was exec('while 1==1:'), it would raise an error. That means that when making the shell, I cant just have it execute raw input. – DevilApple227 Apr 01 '16 at 02:07

1 Answers1

0

The source code for IDLE is in the Python standard library, under the idlelib package. You can look at the source to see how they implement everything.

idlelib is a lot of code, so it might be overwhelming to try to go through it. The code module provides a Python implementation of Python's interactive mode; you could go through the source code for that to get an idea of how you could do things.

user2357112
  • 260,549
  • 28
  • 431
  • 505