An Emacs mode for editing Python code

"IndentationError: expected an indented block" when execute buffer

Asked by Alejandro Weinstein on 2012-09-24

Hi:

Whit the following code

if __name__ == '__main__':
    print 'hello'

when I execute the buffer (C-c C-c), I get the following error:

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/python-12258Tya.py", line 4
    import os; os.chdir("/home/ajw")
         ^
IndentationError: expected an indented block

If I execute code without indentation, the script is executed as expected. Also, if I add a statement without indentation before the first line, the script is executed as expected. For instance, the following code is executed as expected:

a = 1
if __name__ == '__main__':
    print 'hello'

I'm running emacs 24 and the last revision (1089) of python-mode. My python-mode configuration is

(setq py-install-directory "~/.emacs.d/python-mode")
(add-to-list 'load-path py-install-directory)
(require 'python-mode)

Any idea about what can be the problem?

Alejandro.

Question information

Language:
English Edit question
Status:
Answered
For:
python-mode.el Edit question
Assignee:
No assignee Edit question
Last query:
2012-09-24
Last reply:
2012-09-25

I also observe this behavior. I think this should be converted to a bug report.

> I also observe this behavior. I think this should be converted to a bug report.

Done:
https://bugs.launchpad.net/python-mode/+bug/1055569

Andreas Roehler (a-roehler) said : #3

committed a fix, thanks for the report

Can you help with this problem?

Provide an answer of your own, or ask Alejandro Weinstein for more information if necessary.

To post a message you must log in.