Skip to content

Commit 8dbff77

Browse files
authored
Merge pull request #75 from higaski/python39_array_fix
Fix array.tostring for Python 3.9
2 parents d4ce57b + 15221a8 commit 8dbff77

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python/nuc.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def ba(x):
3232
else:
3333
return array.array('B', str(x))
3434

35+
def array2bytes(a):
36+
if hasattr(array.array, 'tostring'):
37+
return a.tostring()
38+
else:
39+
return a.tobytes()
40+
3541
class ForthException(Exception):
3642
def __init__(self, value):
3743
self.value = value
@@ -122,7 +128,7 @@ def dlit(self, d):
122128
def pops(self):
123129
n = self.d.pop()
124130
a = self.d.pop()
125-
return self.ram[a:a+n].tostring().decode("utf-8")
131+
return array2bytes(self.ram[a:a+n]).decode("utf-8")
126132

127133
# Start of Forth words
128134
#
@@ -411,7 +417,7 @@ def xt(self, c):
411417

412418
def SFIND(self):
413419
(a, n) = self.d[-2:]
414-
s = self.ram[a:a+n].tostring().decode("utf-8").upper()
420+
s = array2bytes(self.ram[a:a+n]).decode("utf-8").upper()
415421
# print('HERE', s.decode("utf-8"), self.dict)
416422
if s in self.dict:
417423
x = self.dict[s]

0 commit comments

Comments
 (0)