-
Notifications
You must be signed in to change notification settings - Fork 2
/
code.py
51 lines (45 loc) · 1.26 KB
/
code.py
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
import os
try:
from tdeck_repl import input
except:
pass
try:
from codeop import compile_command
except:
pass
if 'virtcode.py' in os.listdir('/'):
import virtcode
print("Repl in (Circuit-)Python")
__cmd = ""
while True:
if 'compile_command' in dir():
# 9.0.0 alpha 7 or later supports multiple line statements
__line = input(",,, " if __cmd else "=>> " )
if __cmd:
__cmd += ("\n" + (" " if __line != "" else "") + __line)
else:
if __line.lower() == 'exit':
break
__cmd = __line
try:
if compile_command(__cmd):
exec(compile_command(__cmd))
__cmd = ""
except Exception as __err:
print("*ERROR* Exception:",str(__err))
__cmd = ""
else:
# Pre 9.0.0 alpha 7 code (single line statments only)
__line = input("=>> ")
if __line.lower() == 'exit':
break
__result = None
try:
exec('__result='+__line)
except:
try:
exec(__line)
except Exception as err:
print("*ERROR* Exception:",str(err))
if __result != None and __line.find('=') == -1:
print(__result)