helloB helloB - 1 year ago 61
Python Question

Convert .py files to correct encoding for Python 3

I just pulled from a git repo where the users are on Python 2. My system is running Python 3 and with no changes in the code, I am getting this error:

TabError: inconsistent use of tabs and spaces in indentation

It appears that the solution is to change the char set encoding of the
files, but working in emacs, I'm not clear how to do this. I'm seeing these instructions:


but I don't understand how to apply these for utf-8. I'd appreciate any suggestions.

Answer Source

Exists a command untabify:

Convert all tabs in region to multiple spaces, preserving columns. If called interactively with prefix ARG, convert for the entire buffer.

I.e. call it with C-u to convert all TABs in buffer.

As comment points out correctly: tabify does the inverse, converts multiple spaces to tabs - while using spaces seems a common convention not just in Python.