Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"The hands that help are better far than the lips that pray." -- Robert G. Ingersoll


devel / comp.lang.python / Re: Baffled by readline module

SubjectAuthor
o Re: Baffled by readline moduleGrant Edwards

1
Re: Baffled by readline module

<mailman.2259.1678468365.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22342&group=comp.lang.python#22342

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: grant.b....@gmail.com (Grant Edwards)
Newsgroups: comp.lang.python
Subject: Re: Baffled by readline module
Date: Fri, 10 Mar 2023 09:12:41 -0800 (PST)
Lines: 68
Message-ID: <mailman.2259.1678468365.20444.python-list@python.org>
References: <640a3318.020a0220.67dbd.001a@mx.google.com>
<640b40c4.920a0220.da552.0107@mx.google.com> E5796AC4DAFB9FCCB9BA9@SJ0PR14MB5864.namprd14.prod.outlook
.com> <640b6509.020a0220.2b13.05db@mx.google.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 65rtC7uuiN+NaDnNNzk7EQXAQifeFl6c2Irf0qjkvrfQ==
Return-Path: <grant.b.edwards@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=pZiGIr8b;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; '(e.g.': 0.05;
'subject:module': 0.07; 'wrong.': 0.07; 'apparently': 0.09;
'commands.': 0.09; 'etc.).': 0.09; 'linux': 0.09; 'module:': 0.09;
'import': 0.15; 'box.': 0.16; 'bye': 0.16;
'from:addr:grant.b.edwards': 0.16; 'from:name:grant edwards':
0.16; 'importing': 0.16; 'intro': 0.16; 'received:209.85.166.175':
0.16; 'received:mail-il1-f175.google.com': 0.16; 'says:': 0.16;
'usage,': 0.16; 'wrote:': 0.16; 'python': 0.16; 'to:addr:python-
list': 0.20; 'input': 0.21; 'run': 0.23; 'header:User-Agent:1':
0.30; 'seem': 0.31; 'module': 0.31; 'received:google.com': 0.34;
'received:209.85.166': 0.35; 'from:addr:gmail.com': 0.35;
'system,': 0.36; 'received:209.85': 0.37; 'class': 0.37; 'file':
0.38; 'received:209': 0.39; 'list': 0.39; 'use': 0.39; 'prompt':
0.39; "there's": 0.61; 'forward': 0.62; 'i\xe2\x80\x99ve': 0.62;
'true': 0.63; 'our': 0.64; 'back': 0.67; 'per': 0.68; 'right':
0.68; 'it:': 0.69; 'left': 0.83; 'editing': 0.84; 'inherit': 0.84;
'meets': 0.91; 'line,': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20210112; t=1678468362;
h=to:content-transfer-encoding:mime-version:user-agent:references
:subject:from:date:message-id:from:to:cc:subject:date:message-id
:reply-to; bh=zTV2zHV+8wgpDu1zp9Z6zJlmmRWHZ+z55E8YgkmwBz4=;
b=pZiGIr8b4z7o9PRNkdTa5/Fr6dYbG1o661QzWMIdRL1ggKupzGtZAL1Hn7Cdl4/7Bd
DwUF8HMGzOa2w/MfTttLlKXT24snXDnUuY6qzY61vs07EdJTHcS7OjZVU2G5Uj1STNkL
34/cg1AiXERgeaePSYUIExp/fsDXal3eHqMUAVAkYr3GlRAMT2grXB8mVHNAq1j6WAyB
vOhnxSbdQHDNx2m35NCjz+wPBdVy47u8Y5dIyDIJhHbC29QjToPwtCB68ipujgYFpuqa
NDC1QGVmZoCR/iJaix30ixa2N8sB4BHyPJH79Mieo8rOJ435+DQ4em8qvTvP5/VMvcGu
mm9w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112; t=1678468362;
h=to:content-transfer-encoding:mime-version:user-agent:references
:subject:from:date:message-id:x-gm-message-state:from:to:cc:subject
:date:message-id:reply-to;
bh=zTV2zHV+8wgpDu1zp9Z6zJlmmRWHZ+z55E8YgkmwBz4=;
b=aRwrVjfhZFaN1cenahximKYDrjU/m31vqwhYs6h4Zjd9rijETs6/LcX2kWgXtJrZoa
N0vb/atsvOCFD+HczLXGA+bIp2wEvZDqblJdJhU+QOGpnyt0PzDa+DPyTEKIN2dTaET1
QhE+LGWh4yHw9k4TvRfG6ixAQl5/EgqT9/Pht4qgIFju30taaDMvOSiBZqCiAgAMvDgk
aAk01pUyGpE39yz6QvUxmfbmAUh6BYDVx1dkLQVnDanQ0U7HGK4jsQQnMK9jGxitHyQU
jMCi7l0Kcul+br+J9xc8EcO/81mogvn2tMNoVedNwKWmZz9YXyKYaoFwdyCtBdTVW5KD
/rfQ==
X-Gm-Message-State: AO0yUKUovmUrYgNrRMp21p973rNDke3/rvfnKcpRzkK6MURo9JrEIEPT
GUIrWwk1UHJ5ObdHvUyu0zkNW+aUNfA2rA==
X-Google-Smtp-Source: AK7set/6vLBDmQ1Ipd7ZXAxRqXq8HWy6aTcU+/5pFlYJOUDOmfAYbveiaNg/H5BikyACGqV7fG9AXQ==
X-Received: by 2002:a05:6e02:13ee:b0:316:fcbe:627b with SMTP id
w14-20020a056e0213ee00b00316fcbe627bmr5264188ilj.4.1678468361942;
Fri, 10 Mar 2023 09:12:41 -0800 (PST)
User-Agent: slrn/1.0.3 (Linux)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <640b6509.020a0220.2b13.05db@mx.google.com>
X-Mailman-Original-References: <640a3318.020a0220.67dbd.001a@mx.google.com>
<640b40c4.920a0220.da552.0107@mx.google.com> E5796AC4DAFB9FCCB9BA9@SJ0PR14MB5864.namprd14.prod.outlook
.com>
 by: Grant Edwards - Fri, 10 Mar 2023 17:12 UTC

On 2023-03-10, Weatherby,Gerard <gweatherby@uchc.edu> wrote:

> On our Linux systems, I can up-arrow to go back to prior commands
> and use the left and right arrows to navigate a line. The
> functionality may be provided internally by readline. I’ve never had
> to dig into it because it meets my needs out of the box.

Apparently the cmd.Cmd docs are wrong. It says:

If the readline module is loaded, input will automatically
inherit bash-like history-list editing (e.g. Control-P scrolls
back to the last command, Control-N forward to the next one,
Control-F moves the cursor to the right non-destructively,
Control-B moves the cursor to the left non-destructively, etc.).

On my Python 3.10.10 Linux system, cmd.Com itself is importing the
readline module unconditionally when I call cmdloop(). There's no 'if'
about it.

[It's moot for my current usage, because my application allows
multiple commands per input line, and I don't see how cmd.Cmd can
support that.]

Here's my application that seem to show that cmd.Cmd.cmdloop() is
importing the readline module:

-------------------------------testit.py--------------------------------
import sys
print('readline' in sys.modules)
import cmd
print('readline' in sys.modules)

class MyShell(cmd.Cmd):
intro = 'Welcome to my shell. Type help or ? to list commands.\n'
prompt = '(what) '
file = None

def do_what(self,arg):
print('readline' in sys.modules)
def do_bye(self, arg):
print('Good bye')
return True

print('readline' in sys.modules)

if __name__ == '__main__':
print('readline' in sys.modules)
MyShell().cmdloop()
------------------------------------------------------------------------

And here's what I see when I run it:

------------------------------------------------------------------------
$ python testit.py
False
False
False
False
Welcome to my shell. Type help or ? to list commands.

(what) what
True
(what) bye
Good bye
$ ------------------------------------------------------------------------

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor