Я пытаюсь оценить некоторые команды Python в SublimeREPL, но каждая новая команда вызывает IndentationError. Код работает, если я отправляю его по одной строке за раз.Python IndentationError: Sublime Text 2 using SublimeREPL
Вот попытка на примере ...
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)
, который вычисляет ...
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
Однако, если я ставлю некоторые строки комментария символы перед каждой строкой он работает нормально, за исключением для конечных «... ... ... ...»
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)
#
После того, как оно было отправлено, я должен переключиться на REPL и нажмите Enter на строке с помощью «... ... ... ...» для ее оценки.
>>> 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)
#
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Я новичок в Python, поэтому прошу прощения, если у меня что-то очень простое. Я пробовал искать везде для ответа.