2

When I user TAB to indent my code, Some times there is a >> sign in the beginning of the line and some times not.

This happens automatically. enter image description here

when ever that happens, python results in error for indentation.

Indentation error

But on this line, when I press the single tab it indents the code automatically to the correct position. So it is more convenient if it happens, but python does not parse it.

Dos any one also has faced such a problem?

Ashish
  • 133
  • 2
  • 1
    Do you have tools -> indentation checked off as Python? Looks like you're using tabs on some parts of the file and spaces on the other. – Nephilim Jul 09 '20 at 09:37

1 Answers1

2

When I use TAB to indent my code, sometimes there is a >> sign in the beginning of the line and some times not.

Each >> represents a Tab character in KATE (these can appear anywhere).

Having >> at the beginning of a line means that a Tab character is present and is being used to indent that line. When >> is missing but a line is still indented, this means that the characters used at the beginning of that line for indention are spaces (Whitespace characters).

Whenever that happens, Python returns an error for indentation.

If you have some lines indented with >> and some without, then you are using mixed tabs and spaces for indentation (mixed Tab characters and Whitespace characters). Python will not parse this. You must use either all tabs or all spaces for indentation, throughout the entire document.

KATE has an easy access menu for selecting indentation settings:

KATE Editor - Tabs and Spaces - Settings

These settings control what is placed in the document when you press the TAB key. I would highly recommend Soft Tabs (Spaces) as shown above. This way, you can use the TAB key and spaces when writing code and Python will still be able to parse things correctly.

If you need to ensure an entire document uses the same type of indentation, you can:

  • Set your preferred indentation settings (ex. using the menu above).

  • Use Edit → Select All from the main menu to select all the text in the document.

  • Use Tools → Clean Indentation (again from the main menu) to apply the current indentation settings to everything you have selected.

Anaksunaman
  • 16,718
  • 4
  • 38
  • 45