Nauč se Python > Materiály > Snake Workshop for PyLadies > Preparation > Editor installation > Kate

Installation of Kate #

On Linux, Kate is installed like any other program.

Fedora
$ sudo dnf install kate
Ubuntu:
$ sudo apt-get install kate

If you use a different Linux, I assume that you know how to install programs. :)

For Windows and macOS, Kate can be downloaded from the homepage.

Setup #

Line numbering

In the View menu, select Show Line Numbers.

Indentation

In the Settings menu, select Configure Kate.

There in Editing select Indentation, and set there:

  • Default indentation mode: Python
  • Indent using: Spaces
  • Tab Width: 4 characters
  • Indentation width: 4 characters
  • Backspace key in leading blank space unindents
Syntax highlighting

works automatically, but the way of coloring is chosen based on the file extension - for example, .py for Python.

Therefore, as soon as you create a new file in this editor, you should save it under the correct name as soon as possible.

Indentation practice #

As already mentioned, in Python it is important how many spaces a line starts with. Therefore, it will be useful for us to know how to quickly indent blocks of text. Let's see how to do it.

Copy this text into the editor:

OPHELIA:
Good my lord,
How does your honour for this many a day?
HAMLET:
I humbly thank you; well, well, well.
OPHELIA:
My lord, I have remembrances of yours
That I have longed long to re-deliver.
I pray you, now receive them.
HAMLET:
No, not I.
I never gave you aught.
OPHELIA:
My honour’d lord, you know right well you did,
And with them words of so sweet breath compos’d
As made the things more rich; their perfume lost,
Take these again; for to the noble mind
Rich gifts wax poor when givers prove unkind.
There, my lord.

(An excerpt from Hamlet by W. Shakespeare)

This text is not very clear, so we will try to space it out to make it look like this:

OPHELIA:
    Good my lord,
    How does your honour for this many a day?
HAMLET:
    I humbly thank you; well, well, well.
OPHELIA:
    My lord, I have remembrances of yours
    That I have longed long to re-deliver.
    I pray you, now receive them.
HAMLET:
    No, not I.
    I never gave you aught.
OPHELIA:
    My honour’d lord, you know right well you did,
    And with them words of so sweet breath compos’d
    As made the things more rich; their perfume lost,
    Take these again; for to the noble mind
    Rich gifts wax poor when givers prove unkind.
    There, my lord.

To indent one line, set the cursor at the beginning of the line and press the Tab key. Each time you press it, the line will be indented by 4 spaces.

If you indent too much, you can reduce the indentation using Shift+Tab.

If you want to indent multiple lines at once, select them all and press Tab. You can also "unindent" the whole selection using Shift+Tab.

And that's it! Now you not only have the editor set up, but you also know how to use it.


Toto je stránka lekce z kurzu, který probíhá nebo proběhl naživo s instruktorem.