Command recall

There are many ways to avoid typing within the PyCrust shell. Most of them involve capturing something you have previously entered, modifying it if necessary, and sending it to the Python interpreter.

For example, PyCrust maintains a history of all the commands you have entered in the current session. You can recall any previously entered Python commands (single-line or multi-line) from the command history. Table 4.1 displays a list of keyboard shortcuts that relate to this functionality.

Table 4.1 Keyboard shortcuts related to command recall in the PyCrust shell

Key Combination

Result

Ctrl+Up Arrow

Retrieve previous history item

Alt+P

Retrieve previous history item

Ctrl+Down Arrow

Retrieve next history item.

Alt+N

Retrieve next history item

Shift+Up Arrow

Insert previous history item

Shift+Down Arrow

Insert next history item

F8

Command-completion of history item. (Type a few characters of a previous command and press F8)

Ctrl+Enter

Insert new line into multiline command

As you can see, there are separate commands for retrieving and inserting old commands, distinguished by how PyCrust handles the text entered at the current wxPython prompt. To replace what you have entered, use one of the shortcuts that retrieves a history item. To insert an old command at the caret, use one of the shortcuts that inserts a history item.

Inserting a line into the middle of a multi-line command works differently than inserting into a single-line command. To insert a line into a multi-line command, you can't simply press the Enter key, because that sends the current command to the Python interpreter. Instead, press Ctrl+Enter to insert a break in the current line. If you are at the end of the line, a blank line is inserted after the current line. This process is similar to the way you would cut and paste text in a regular text editor.

The final method of recalling a command is to simply move the caret to the command that you want to recall, and press Enter. PyCrust copies that command to the current Python prompt, and repositions the caret at the end. You can then modify the command, or press Enter again and submit the command to the interpreter.

These shortcuts allow you to develop code incrementally, testing your creation every step of the way. For example, you can define a new Python class, create an instance of that class, and see how it behaves. Then you can go back to the class definition, add more methods or edit the existing methods, and create a new instance. By repeating this as often as you need, you can develop your class definition to the point that it is good enough to cut and paste into your program's source code. Which brings us to our next feature.

0 -1

Responses

  • j
    How recall program in python?
    6 years ago

Post a comment