2 ms·
$ python3 Python 3.10.6 (...snip...) >>> def example(): ... x = 5 ... print("Hello world") File "<stdin>", line 3 pri
by mixmastamyk 4y ago
$ python3
Python 3.10.6 (...snip...)
>>> def example():
... x = 5
... print("Hello world")
File "<stdin>", line 3
print("Hello world")
^
IndentationError: unindent does not match any outer indentation level
Sort of an odd video, haha. But I liked the guy... think we could be friends. ;-)
It's idea is sort of neither here nor there however, regarding whitespace blocks. That we "rent" more often than own is just a reality of the system we find ourselves in. (For example cheap products sell more than expensive ones and that is expected and ok.)
I don't want to optimize my projects around large refactors since I only do it a few times per project, but will read it often.
- compressedgas 4y agoThat's because the REPL has the additional restriction of requiring a definition (or any top level indented block) to end with an blank line. This restriction does not apply when running code from a file.
- mixmastamyk 4y ago$ python3 foo.py File "~/Desktop/foo.py", line 4 print("Hello world") ^ IndentationError: unindent does not match any outer indentation level I didn't understand your statement exactly, but it doesn't seem to be true in any case.
- compressedgas 4y agoThe file: def foo(): bar = 3 print ('4') runs fine when called as a file but when pasted into Python's REPL results in an error: >>> def foo(): ... bar = 3 ... print ('4') File "<stdin>", line 3 print ('4') ^ SyntaxError: invalid syntax However with a blank line after the definition def foo(): bar = 3 print ('4') results in: >>> def foo(): ... bar = 3 ... >>> print ('4') 4
- mixmastamyk 4y agoI see now. The issue was pasting the snippet into a terminal added an extra level of indentation from the post (pre must be indented). This changed the result.