Friday, 15 January 2010

sublimetext2 - Python IndentationError: Sublime Text 2 using SublimeREPL -



sublimetext2 - Python IndentationError: Sublime Text 2 using SublimeREPL -

i trying evaluate python commands in sublimerepl every new command causes indentationerror. code works if send 1 line @ time.

here effort @ example...

class array(object): def __init__(self, length = 0, baseindex = 0): assert(length >= 0) self._data = [0 in range(length)] self._baseindex = baseindex def __copy__(self): result = array(len(self._data)) i, datum in enumerate(self._data): result._data[i] = datum result._baseindex = self._baseindex homecoming result def __len__(self): homecoming 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 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 >>> i, datum in enumerate(self._data): file "<stdin>", line 1 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 >>> homecoming result file "<stdin>", line 1 homecoming result ^ indentationerror: unexpected indent >>> >>> def __len__(self): file "<stdin>", line 1 def __len__(self): ^ indentationerror: unexpected indent >>> homecoming len(self._data) file "<stdin>", line 1 homecoming len(self._data) ^ indentationerror: unexpected indent

however if set line comment characters in before each line works fine except trailing "... ... ... ..."

class array(object): def __init__(self, length = 0, baseindex = 0): assert(length >= 0) self._data = [0 in range(length)] self._baseindex = baseindex # def __copy__(self): result = array(len(self._data)) i, datum in enumerate(self._data): result._data[i] = datum result._baseindex = self._baseindex homecoming result # def __len__(self): homecoming len(self._data) #

after has been sent have switch on repl window , nail come in on line "... ... ... ..." evaluated.

>>> class array(object): def __init__(self, length = 0, baseindex = 0): assert(length >= 0) self._data = [0 in range(length)] self._baseindex = baseindex # def __copy__(self): result = array(len(self._data)) i, datum in enumerate(self._data): result._data[i] = datum result._baseindex = self._baseindex homecoming result # def __len__(self): homecoming len(self._data) # ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

i new python apologize if missing simple. tried looking everywhere answer.

i suspect you've shown code that's not you're running. in actual python script, you've got few newlines separating def's each other (which fine), aren't in pasted section of code here. maybe because of formatting issues here or something.

however, in python, empty line indicates you're done previous section. matters when using interactive interpreter (like in sublimerepl). spaces , indentation matter. in case, it's transferring text interpreter, same thing happens if cutting , paste yourself. it's seeing newline before def __copy__(self), , assuming should evaluate class definition. then, it's seeing def __copy__(self), , noticing has space indenting. causing indentationerror you're receiving.

either comment on already existing bug in sublimerepl's github account, or don't utilize empty lines in code.

python sublimetext2 read-eval-print-loop sublimerepl

No comments:

Post a Comment