-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.

3
  • 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? Commented Apr 1, 2016 at 2:00
  • If I had to make the IDLE shell in Python it would probably look something like this github.com/python/cpython/tree/master/Lib/idlelib Commented Apr 1, 2016 at 2: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. Commented Apr 1, 2016 at 2:07

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.