I am trying to evaluate some Python commands in SublimeREPL but every new command causes an IndentationError. The code works if I send it one line at a time.
Here is an attempt at an example...
class Array(object):
def __init__(self, length = 0, baseIndex = 0):
assert(length >= 0)
self._data = [0 for i in range(length)]
self._baseIndex = baseIndex
def __copy__(self):
result = Array(len(self._data))
for i, datum in enumerate(self._data):
result._data[i] = datum
result._baseIndex = self._baseIndex
return result
def __len__(self):
return len(self._data)
which evaluates to...
IndentationError: unexpected indent
>>> class Array(object):
... def __init__(self, length = 0, baseIndex = 0):
... assert(length >= 0)
... self._data = [0 for i in range(length)]
... self._baseIndex = baseIndex
...
>>> def __copy__(self):
File "<stdin>", line 1
def __copy__(self):
^
IndentationError: unexpected indent
>>> result = Array(len(self._data))
File "<stdin>", line 1
result = Array(len(self._data))
^
IndentationError: unexpected indent
>>> for i, datum in enumerate(self._data):
File "<stdin>", line 1
for i, datum in enumerate(self._data):
^
IndentationError: unexpected indent
>>> result._data[i] = datum
File "<stdin>", line 1
result._data[i] = datum
^
IndentationError: unexpected indent
>>> result._baseIndex = self._baseIndex
File "<stdin>", line 1
result._baseIndex = self._baseIndex
^
IndentationError: unexpected indent
>>> return result
File "<stdin>", line 1
return result
^
IndentationError: unexpected indent
>>>
>>> def __len__(self):
File "<stdin>", line 1
def __len__(self):
^
IndentationError: unexpected indent
>>> return len(self._data)
File "<stdin>", line 1
return len(self._data)
^
IndentationError: unexpected indent
However if I put some line comment characters in before each line it works fine except for the trailing "... ... ... ..."
class Array(object):
def __init__(self, length = 0, baseIndex = 0):
assert(length >= 0)
self._data = [0 for i in range(length)]
self._baseIndex = baseIndex
#
def __copy__(self):
result = Array(len(self._data))
for i, datum in enumerate(self._data):
result._data[i] = datum
result._baseIndex = self._baseIndex
return result
#
def __len__(self):
return len(self._data)
#
After it has been sent I have to switch over to the REPL window and hit enter on the line with the "... ... ... ..." for it to be evaluated.
>>> class Array(object):
def __init__(self, length = 0, baseIndex = 0):
assert(length >= 0)
self._data = [0 for i in range(length)]
self._baseIndex = baseIndex
#
def __copy__(self):
result = Array(len(self._data))
for i, datum in enumerate(self._data):
result._data[i] = datum
result._baseIndex = self._baseIndex
return result
#
def __len__(self):
return len(self._data)
#
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
I am new to Python so I apologize if I am missing something very simple. I tried looking everywhere for this answer.