Search code examples
pythoninputdocumentationhistorysubstitution

Interactive Input Editing and History Substitution (Python Documentation_Ch14)


Scoured the net to find an answer on this doc:

Some versions of the Python interpreter support editing of the current input line and history substitution, similar to facilities found in the Korn shell and the GNU Bash shell. This is implemented using the GNU Readline library, which supports various styles of editing. This library has its own documentation which we won’t duplicate here.

  • Read about Unix but what is this operation called editing of the current input line? (Examples, Resources for Python or a simple example wourd be great)
  • History Substitution... what is that maybe a simple example? Documentation touches on the issue as a know field and doesn't provide any insight on it.

Also cannot crack the line:

Completion of variable and module names is automatically enabled at interpreter startup so that the Tab key invokes the completion function; it looks at Python statement names, the current local variables, and the available module names.

Can anybody provide a simple line explaining this line.


Solution

  • Editing the current input line is common practice.

    For example if I use command prompt and do:

    cd C:\Us
    

    and hit Tab it will auto fill to:

    cd C:\Users\
    

    It just edited the current input line.

    Similarly look up history does the same thing. If I do the following in command prompt:

    > color b --> [Enter]
    > # Now I have an empty command line
    [Up Arrow]
    > color b # Command prompt will fill the current line with what I just used.
    

    Python can do the same thing by looking up variables and packages:

    >>> import foobar
    >>> fo [TAB] --> >>> foobar 
    

    Python auto filled fo to foobar because it knew I imported it by reading through my code. It can do the same for variables (by reading the python code to find variables you defined).

    >>> temp_var = 2
    >>> te [TAB] --> >>> temp_var