├── README.md ├── basicpython.py └── example.svg /README.md: -------------------------------------------------------------------------------- 1 | This is an experiment to edit Python code like BASIC was edited. The idea is imagining this as the default mode on a [Raspberry Pi 400](https://www.raspberrypi.org/products/raspberry-pi-400/). 2 | 3 | It's a mix of modern and retro. 4 | 5 | ![Example](./example.svg) 6 | 7 | -------------------------------------------------------------------------------- /basicpython.py: -------------------------------------------------------------------------------- 1 | print("# Basic Python v0") 2 | 3 | program = [] 4 | top = {} 5 | no_ready = False 6 | 7 | while True: 8 | if no_ready: 9 | line = input() 10 | else: 11 | line = input("READY.\n") 12 | lineno = None 13 | if " " in line: 14 | command, remainder = line.split(" ", 1) 15 | lineno = None 16 | try: 17 | lineno = int(command, 10) 18 | except ValueError: 19 | pass 20 | else: 21 | command = line 22 | no_ready = False 23 | if lineno is not None: 24 | if lineno < 1: 25 | print("Line must be 1+") 26 | else: 27 | if lineno >= len(program): 28 | program.extend([""] * (lineno - len(program))) 29 | program[lineno - 1] = remainder 30 | no_ready = True 31 | elif command.lower() == "list": 32 | for i, line in enumerate(program): 33 | if line: 34 | print(i+1, line) 35 | elif command.lower() == "run": 36 | isolated = {} 37 | try: 38 | exec("\n".join(program), isolated, isolated) 39 | except Exception as e: 40 | print(e) 41 | elif command.lower() == "save": 42 | filename = remainder.strip(" \"") 43 | with open(filename, "w") as f: 44 | f.write("\n".join(program)) 45 | elif command.lower() == "load": 46 | filename = remainder.strip(" \"") 47 | with open(filename, "r") as f: 48 | program = f.readlines() 49 | program = [line.strip("\r\n") for line in program] 50 | else: 51 | try: 52 | exec(line, top, top) 53 | except Exception as e: 54 | print(e) 55 | 56 | -------------------------------------------------------------------------------- /example.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 320 | 343 | 344 | 345 | Linux dalinar 5.10.5-arch1-1 x86_64 11:34:23 up 13:10, 4 users, load average: 0.39, 0.64, 0.78 ~/r/basicpython Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython p Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython python basicpython.py Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython python basicpython.py Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython python basicpython.py Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython python basicpython.py Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython python basicpython.py Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython python basicpython.py Sun 10 Jan 2021 07:34:23 PM UTC ~/r/basicpython python basicpython.py Sun 10 Jan 2021 07:34:23 PM UTC# Basic Python v0READY.t th thi this this this i this is this is this is p this is py this is pyt this is pyth this is pytho this is python this is python this is python e this is python ed this is python edi this is python edit this is python edite this is python edited this is python edited this is python edited b this is python edited l this is python edited li this is python edited lin this is python edited lik this is python edited like this is python edited like this is python edited like b this is python edited like ba this is python edited like bas this is python edited like basi this is python edited like basic this is python edited like basicinvalid syntax (<string>, line 1)h hl he hel hell hello hello hello c hello co hello com hello comp hello compu hello comput hello compute hello computer hello computerp pr pri prin print print( print(" print("h print("he print("hel print("hell print("hello print("hello print("hello p print("hello py print("hello pyt print("hello pyth print("hello pytho print("hello python print("hello python" print("hello python") print("hello python")hello python1 10 10 10 p 10 pr 10 pri 10 prin 10 print 10 print( 10 print(" 10 print("h 10 print("he 10 print("hel 10 print("hell 10 print("hello 10 print("hello 10 print("hello p 10 print("hello py 10 print("hello pyt 10 print("hello pyth 10 print("hello pytho 10 print("hello python 10 print("hello python" 10 print("hello python") 10 print("hello python")r ru run runl li lis list list5 5 5 f 5 fo 5 for 5 for 5 for i 5 for i 5 for i i 5 for i in 5 for i in 5 for i in r 5 for i in ra 5 for i in ran 5 for i in rang 5 for i in range 5 for i in range( 5 for i in range(" 5 for i in range(1 5 for i in range(10 5 for i in range(10) 5 for i in range(10): 5 for i in range(10):expected an indented block (<string>, line 10)10 10 10 p 10 pr 10 pri 10 prin 10 print 10 print( 10 print(" 10 print("h 10 print("he 10 print("hel 10 print("hell 10 print("hello 10 print("hello" 10 print("hello", 10 print("hello", 10 print("hello", i 10 print("hello", i) 10 print("hello", i)hello 0hello 1hello 2hello 3hello 4hello 5hello 6hello 7hello 8hello 9s sa sav save save save " save "h save "he save "hel save "hell save "hello save "hello. save "hello.p save "hello.py save "hello.py" save "hello.py"lo loa load load load " load "c load "co load "cou load "coun load "count load "count. load "count.p load "count.py load "count.py" load "count.py"10 print(i)0123456789load "h load "he load "hel load "hell load "hello load "hello. load "hello.p load "hello.py load "hello.py" load "hello.py"^CTraceback (most recent call last): File "/home/tannewt/repos/basicpython/basicpython.py", line 11, in <module> line = input("READY.\n")KeyboardInterrupt ! ~/r/basicpython 1.5m  Sun 10 Jan 2021 07:35:56 PM UTC ! ~/r/basicpython 1.5m  Sun 10 Jan 2021 07:35:56 PM UTC 346 | --------------------------------------------------------------------------------