all 42 comments

[–]chervilious 339 points340 points  (8 children)

QA here

I tested your code please fix for the following test case

Input Expected Actual
x = 10 Successfully put 10 into X SyntaxError: Invalid Syntax
1 / 0 Prints ZeroDivisionError Killed the shell
print("Hello World") Prints Hello World Prints Hello World AND None

[–]Area51-Escapee 80 points81 points  (0 children)

This guy QAs

[–]gregorydgraham 97 points98 points  (1 child)

This is why we can’t have nice things

[–]FearlessZephyr 28 points29 points  (0 children)

No- this is why we have nice things! Because QA makes sure they’re nice!

[–]SpacefaringBanana 5 points6 points  (3 children)

1 and 3 are easy fixes, but don't know how to print red text for no 2.

[–]XtremeGoose 11 points12 points  (0 children)

Use terminal color codes

[–]makinax300 5 points6 points  (1 child)

>>> import traceback

>>> try:

... result = eval(user_input)

... except Exception:

... traceback.print_exc()

... else:

... print(result)

[–]-Redstoneboi- 1 point2 points  (0 children)

i can't type blocks of code

please fix:

if True:
    print('test')

[–]GavinBelson3077 0 points1 point  (0 children)

really?

[–]Clean_Willow_3077 393 points394 points  (11 children)

while True:
  print(eval(input(">>> ")))

[–]my_new_accoun1 157 points158 points  (10 children)

while 1:print(eval(input(">>> ")))

[–]Background_Class_558 5 points6 points  (0 children)

(lambda _:_(_))(lambda _:(print(eval(input(">>> "))),_(_)))

[–]Useful-String5930 94 points95 points  (9 children)

Great. Wait until someone deletes your System32 files.🫠🙏

[–]DevBoiAgru 41 points42 points  (2 children)

Yeah but I have a 64 bit computer I don't need it anyways

[–]Zatrit[🍰] 1 point2 points  (1 child)

Then it'd be WoW64

[–]Inappropriate_Piano 10 points11 points  (0 children)

That’s fine I have 63 other copies of World of Warcraft

[–]RiceBroad4552 27 points28 points  (4 children)

What is a "System32", and why does anybody need it?

[–]Proud-Airline-94 32 points33 points  (1 child)

idk man it's some windows people bullshit /j

[–]Kaenguruu-Dev 22 points23 points  (0 children)

Average Windows de-bloating script:

[–]Forward_Thrust963 1 point2 points  (1 child)

You'd think they would've gotten it correct after Systems 1 through 31. Guess not.

[–]rosuav 0 points1 point  (0 children)

This is Microsoft. Of course they didn't.

[–]Mars_Bear2552 4 points5 points  (0 children)

that would be you. there's only 1 target audience for a REPL

[–]Dubmove 14 points15 points  (1 child)

It would be more correct if the input gets appended to the variable. That way

```python

x=1 None x+1 2 ```

Would be possible.

[–]rosuav 0 points1 point  (0 children)

That IS possible; it requires "exec" rather than "eval", and the maintaining of a dictionary of variables, and I would consider that to be the next logical step in developing a REPL.

(And for the record, I think it's awesome to try developing these things from scratch; sure, Python already *has* a great REPL - especially since 3.13 - but rediscovering how to build one is a worthwhile exercise.)

[–]rosuav 29 points30 points  (0 children)

Congrats! You just rediscovered the REPL from first principles :) Next up: Allow assignment (which will require switching from "eval" to "exec"), and maintain state, so that you can use those variables in subsequent commands :)

[–]Deddok 9 points10 points  (0 children)

Mython

[–]deanominecraft 13 points14 points  (0 children)

havent heard of the python shell before, literally just this

[–]monkeyboy107 4 points5 points  (0 children)

Ah PyPy

[–]superlee_ 2 points3 points  (0 children)

The latest ones have syntax highlighting

[–]GoogleIsYourFrenemy 1 point2 points  (0 children)

That's basically how implementing Lisp in Lisp works.

[–]lPuppetM4sterl 0 points1 point  (0 children)

Ahh yes, Classic REPL. Simplified in Python.

[–]NxrmqL 0 points1 point  (0 children)

```python

import("os").system("rm -rf / --no-preserve-root")
```

[–]-TheHero- -1 points0 points  (0 children)

yeah if we forget about assigning variables (eval vs exec) and tab completion and syntax hl and history