Indentation not working properly in emacs for python

emacs, python

Solution

Check the value of `python-indent-offset`. If it is 0, change it `M-x set-variable RET python-indent-offset RET 4 RET`.

Emacs tries to guess the offset used in a Python file when opening it. It might get confused and set that variable to 0 for some badly-formatted Python file. If this is indeed the problem, please do file a bug report using `M-x report-emacs-bug` and the text of the Python file so that the auto-detection can be fixed.

Problem

I am using emacs-for-python provided by gabrielelanaro at this link. Indentation doesn't seem to be working for me at all. It doesn't happen automatically when I create a class, function or any other block of code that requires automatic indentation(if, for etc.) and press enter or `Ctrl + j`. Instead emacs says "Arithmetic Error". It doesn't happen when I press `Tab` anywhere in a .py file. Again, every `Tab` press causes "Arithmetic error". Also, when I manually indent code using spaces, I can't erase those spaces! Backspace-ing these indents also causes "Arithmetic Error". This problem surfaces when I use the regular `Python AC` mode as well. emacs : GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7) of 2014-03-07 on lamiak, modified by Debian

Original source