Python Indentation Problems in Geany

Asked

Viewed 1,047 times

0

Since I switched from IDE ( moved from Pycharm to Geany ), I started having a lot of problems with the error: "inconsistent use of tabs and Spaces in indentation".

I would like to know a way to solve this constant problem, use only tab for indentation, no spaces or anything else.

  • Put exactly what gives trouble for us to see, surely is mixing things up. In Python it ends up being better to use spaces, unless the person is disciplined and knows well how to find the problem when it occurs, which is not your case.

  • Can you see which characters are tabs and which are spaces or they all appear invisible to you?

  • Victor - All appear invisible.

  • Maniero - https://pastebin.com/1RSwLR2h

  • You said you only use tab, only almost everything is with space. Just from the converted Pastebin

  • As I see if they are spaces or tabs?

  • Virtually every good IDE has the option to show "invisible characters" (for example, showing spaces like centered dots and tabs like arrows). Enabling this option can help identify and resolve the problem.

Show 2 more comments

3 answers

2

geany uses tab by default in identation.

Change Edit > Preferences > Editor > Indentation Tabs for Spaces.

Python uses, by convention, 4 spaces for ident (Pycharm standard), and should not be mixed tab and space to avoid compilation error.

  • Ah, that must have been it then, because " I transferred " Pycharm’s code to Geany

  • pycharm follows the PEP8 convention, accusing the misuse of tabs in the code.

1

Python usually presents these errors because the compiler relies heavily on indentation. It is recommended not to use copy and paste too much by grabbing code from other corners or websites because when you do this they may come with different spacing when you insert into the IDE of your preference.

You can also use Sublime Text as a different way to make your codes because it is a good editor for this type of thing. I also changed from Pycharm and currently use Sublime to program in Python because it has a good indentation.

  • I understood, by the way, I did not copy and paste the code no, I am studying Pygame and " developing " the same game that of the course, for tests.

0

Looking at the code you’ve posted in an editor that lets you view tabs and spaces so they’re not invisible (Notepad++):

visualizado

All the rest of the file is identado with spaces. I recommend to always identar with spaces, that give less headache.

  • Okay, I’ll start indenting with spaces.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.