- Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbasicpython.py
More file actions
Latest commit
96 lines (91 loc) · 2.83 KB
/
Copy pathbasicpython.py
File metadata and controls
96 lines (91 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Developed by Scott Shawcroft (@tannewt) https://github.com/tannewt/basicpython
#
# 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
#
importos
if__name__=="PyDOS":
globalenvVars
nCols=int((int(envVars["_scrWidth"])-1)/16)
else:
nCols=4
print("# Basic Python v0")
program= []
top= {}
no_ready=False
whileTrue:
ifno_ready:
line=input()
else:
line=input("READY.\n")
lineno=None
if" "inline:
command, remainder=line.split(" ", 1)
lineno=None
try:
lineno=int(command, 10)
exceptValueError:
pass
else:
command=line
remainder=""
no_ready=False
iflinenoisnotNone:
iflineno<1:
print("Line must be 1+")
else:
iflineno>=len(program):
program.extend([""] * (lineno-len(program)))
program[lineno-1] =remainder
no_ready=True
elifcommand.lower() =='new':
program.clear()
elifcommand.lower() =='dir':
wideCount=0
fordirinos.listdir():
ifos.stat(dir)[0] & (2**15) ==0:
if (wideCount%nCols) ==0:
print()
wideCount+=1
print(("<"+dir+">"+" "*(13-len(dir)))[:15]+" ",end="")
fordirinos.listdir():
ifos.stat(dir)[0] & (2**15) !=0:
if (wideCount%nCols) ==0:
print()
wideCount+=1
print((dir+" "*(15-len(dir)))[:15]+" ",end="")
print()
elifcommand.lower() =="del":
ifremainder.strip(" \"") !="":
ifremainder.strip(" \"") inos.listdir():
os.remove(remainder.strip(" \""))
else:
print("Unable to delete: "+remainder.strip(" \"")+". File not found.")
else:
print("No file specified!")
elifcommand.lower() =="list":
fori, lineinenumerate(program):
ifline:
print(i+1, line)
elifcommand.lower() =="run":
isolated= {}
try:
exec("\n".join(program), isolated, isolated)
exceptExceptionase:
print(e)
elifcommand.lower() =="save":
filename=remainder.strip(" \"")
withopen(filename, "w") asf:
f.write("\n".join(program))
elifcommand.lower() =="load":
filename=remainder.strip(" \"")
withopen(filename, "r") asf:
program=f.readlines()
program= [line.strip("\r\n") forlineinprogram]
elifcommand.lower() in ["exit","quit","dos"]:
break
else:
try:
exec(line, top, top)
exceptExceptionase:
print(e)