Re: Baffled by readline module

2023-03-10 Thread Cameron Simpson
On 10Mar2023 23:11, Weatherby,Gerard wrote: This is the implementation of cmd.Cmd (Python 3.9). As you can see in cmdloop(), the import is already wrapped, and the readline feature can be turned off explicitly by passing None to the completekey in the constructor. This isn't strictly true,

Re: Baffled by readline module

2023-03-10 Thread Weatherby,Gerard
on Date: Friday, March 10, 2023 at 5:15 PM To: python-list@python.org Subject: Re: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 10Mar2023 09:12, Grant Edwards wrote: >On 2023-03-10, Weatherby,G

Re: Baffled by readline module

2023-03-10 Thread Grant Edwards
On 2023-03-10, Cameron Simpson wrote: > On 10Mar2023 09:12, Grant Edwards wrote: >>On 2023-03-10, Weatherby,Gerard 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

Re: Baffled by readline module

2023-03-10 Thread Cameron Simpson
On 10Mar2023 09:12, Grant Edwards wrote: On 2023-03-10, Weatherby,Gerard 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

Re: Baffled by readline module

2023-03-10 Thread Eryk Sun
On 3/9/23, Greg Ewing via Python-list wrote: > On 10/03/23 4:00 pm, 2qdxy4rzwzuui...@potatochowder.com wrote: >> My ~/.pythonrc contains the following: >> >> import readline >> import rlcompleter >> readline.parse_and_bind( 'tab: complete' ) > > I don't have a ~/.pythonrc, so

Re: Baffled by readline module

2023-03-10 Thread Simon Ward
On Fri, Mar 10, 2023 at 06:37:56AM -0800, Grant Edwards wrote: On 2023-03-10, Weatherby,Gerard wrote: I'll have to remember that one. It doesn't really fit my current use case, but there are others where it would work nicely. However, cmd.Cmd does not provide command recall and editing.

Re: Baffled by readline module

2023-03-10 Thread Grant Edwards
On 2023-03-10, Weatherby,Gerard 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.

Re: Baffled by readline module

2023-03-10 Thread Weatherby,Gerard
Edwards Date: Friday, March 10, 2023 at 9:39 AM To: python-list@python.org Subject: Re: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 2023-03-10, Weatherby,Gerard wrote: > I would say, “No, readl

Re: Baffled by readline module

2023-03-10 Thread Grant Edwards
On 2023-03-10, Weatherby,Gerard wrote: > I would say, “No, readline is not the right tool.” > > cmd.Cmd is: https://docs.python.org/3/library/cmd.html. I have a > couple of cmd.Cmd modules, one of which I use daily and the other > weekly. I'll have to remember that one. It doesn't really fit my

Re: Baffled by readline module

2023-03-10 Thread Weatherby,Gerard
@python.org Subject: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** In an interactive command-line Python program on Linux, I want to be able to read a line at a time from stdin, providing command line

Re: Baffled by readline module

2023-03-10 Thread gene heskett
On 3/9/23 20:31, 2qdxy4rzwzuui...@potatochowder.com wrote: I was with you until that part of the small wooden box. :-) So was I, but we all put that off as long as we can. I retired 22 years ago. We're not really an industry that has a concept of retirement. Which is why I'm still here

Re: Baffled by readline module

2023-03-09 Thread Greg Ewing via Python-list
On 10/03/23 4:00 pm, 2qdxy4rzwzuui...@potatochowder.com wrote: My ~/.pythonrc contains the following: import readline import rlcompleter readline.parse_and_bind( 'tab: complete' ) I don't have a ~/.pythonrc, so that's not what's doing it for me. -- Greg --

Re: Baffled by readline module

2023-03-09 Thread Greg Ewing via Python-list
On 10/03/23 2:57 pm, Chris Angelico wrote: import sys; "readline" in sys.modules Is it? Yes, it is -- but only when using the repl! If I put that in a script, I get False. My current theory is that it gets pre-imported when using Python interactively because the repl itself uses it. -- Greg

Re: Baffled by readline module

2023-03-09 Thread 2QdxY4RzWzUUiLuE
On 2023-03-09 at 19:11:56 -0800, Grant Edwards wrote: > On 2023-03-10, 2qdxy4rzwzuui...@potatochowder.com > <2qdxy4rzwzuui...@potatochowder.com> wrote: > If you run this application from the command line, you get command > recall and editing when entering strings at the "cmd:" prompt? > >

Re: Baffled by readline module

2023-03-09 Thread Grant Edwards
On 2023-03-10, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: > On 2023-03-10 at 12:57:48 +1100, > Chris Angelico wrote: > >> On Fri, 10 Mar 2023 at 12:56, Greg Ewing via Python-list >> wrote: >> > >> > On 10/03/23 1:46 pm, Grant Edwards wrote: >> > > That's not

Re: Baffled by readline module

2023-03-09 Thread 2QdxY4RzWzUUiLuE
On 2023-03-10 at 12:57:48 +1100, Chris Angelico wrote: > On Fri, 10 Mar 2023 at 12:56, Greg Ewing via Python-list > wrote: > > > > On 10/03/23 1:46 pm, Grant Edwards wrote: > > > That's not how it acts for me. I have to "import readline" to get > > > command line recall and editing. > > > >

Re: Baffled by readline module

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 12:56, Greg Ewing via Python-list wrote: > > On 10/03/23 1:46 pm, Grant Edwards wrote: > > That's not how it acts for me. I have to "import readline" to get > > command line recall and editing. > > Maybe this has changed? Or is platform dependent? > > With Python 3.8 on

Re: Baffled by readline module

2023-03-09 Thread Greg Ewing via Python-list
On 10/03/23 1:46 pm, Grant Edwards wrote: That's not how it acts for me. I have to "import readline" to get command line recall and editing. Maybe this has changed? Or is platform dependent? With Python 3.8 on MacOSX I can use up arrow with input() to recall stuff I've typed before, without

Re: Baffled by readline module

2023-03-09 Thread 2QdxY4RzWzUUiLuE
On 2023-03-10 at 11:02:52 +1100, Chris Angelico wrote: > Traditional retirement: Work till you're 60 or 65 or whatever, then > society pats you on the head, calls you a "senior citizen", and lets > you go and be idle till you die (which might be prematurely soon). Sounds like Free Four¹: The

Re: Baffled by readline module

2023-03-09 Thread Grant Edwards
On 2023-03-10, Greg Ewing via Python-list wrote: > On 10/03/23 10:08 am, Grant Edwards wrote: >> It finally dawned on me after seeing an example I found elsewhere that >> you don't call some module method to fetch the next user-entered line. >> >> You call the input() built-in. >> >> Having a

Re: Baffled by readline module

2023-03-09 Thread Greg Ewing via Python-list
On 10/03/23 12:43 pm, Grant Edwards wrote: When a computer dies, I generally just cp -a (or rsync -a) $HOME to a new one. Same here, more or less. My current machine has multiple archaeological layers going back about 5 generations of technology... -- Greg --

Re: Baffled by readline module

2023-03-09 Thread Greg Ewing via Python-list
On 10/03/23 11:43 am, Chris Angelico wrote: import readline print("Pseudo-prompt: ", end="") msg1 = input() msg2 = input("Actual prompt: ") print(repr(msg1)) print(repr(msg2)) At each of the prompts, type a bit of text, then backspace it all the way. The actual prompt will remain, but the

Re: Baffled by readline module

2023-03-09 Thread Greg Ewing via Python-list
On 10/03/23 10:59 am, Cameron Simpson wrote: I think this might be the common case of a module which wraps another library It's not quite the same thing, though -- the library it wraps is already hooked into things behind the scenes in ways that may not be obvious. (Unless you're Dutch?) --

Re: Baffled by readline module

2023-03-09 Thread Greg Ewing via Python-list
On 10/03/23 10:08 am, Grant Edwards wrote: It finally dawned on me after seeing an example I found elsewhere that you don't call some module method to fetch the next user-entered line. You call the input() built-in. Having a module modify the behavior of a built-in makes me cringe. Importing

Re: Baffled by readline module

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 10:51, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2023-03-09 at 15:02:53 -0800, > Grant Edwards wrote: > > > Yeesh. What's _really_ embarassing is that I just stumbled across a > > small test program with which I had apparently figured this out 10-12 > > years ago.

Re: Baffled by readline module

2023-03-09 Thread Cameron Simpson
On 09Mar2023 13:08, Grant Edwards wrote: Having a module modify the behavior of a built-in makes me cringe. Maybe. But input(), like print(), is one of those funky conveniences for human interaction. I'm somewhat ok with that. If for no other reason than to make keyboard arrow keys act as

Re: Baffled by readline module

2023-03-09 Thread 2QdxY4RzWzUUiLuE
On 2023-03-09 at 15:02:53 -0800, Grant Edwards wrote: > Yeesh. What's _really_ embarassing is that I just stumbled across a > small test program with which I had apparently figured this out 10-12 > years ago. Must be about time to retire... Retiring doesn't help. :-) I retired almost five

Re: Baffled by readline module

2023-03-09 Thread Grant Edwards
On 2023-03-09, Chris Angelico wrote: > On Fri, 10 Mar 2023 at 10:04, Grant Edwards wrote: > >> Yeesh. What's _really_ embarassing is that I just stumbled across a >> small test program with which I had apparently figured this out >> 10-12 years ago. Must be about time to retire... > > You

Re: Baffled by readline module

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 10:04, Grant Edwards wrote: > > Yeesh. What's _really_ embarassing is that I just stumbled across a > small test program with which I had apparently figured this out 10-12 > years ago. Must be about time to retire... > You expect yourself to remember test programs you

Re: Baffled by readline module

2023-03-09 Thread Grant Edwards
On 2023-03-09, Grant Edwards wrote: > On 2023-03-09, Cameron Simpson wrote: > >> [...] >>>It finally dawned on me after seeing an example I found elsewhere that >>>you don't call some module method to fetch the next user-entered line. >>> >>>You call the input() built-in. >> >> Ah. That's not

Re: Baffled by readline module

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 09:20, Grant Edwards wrote: > > On 2023-03-09, Cameron Simpson wrote: > > > [...] > >>It finally dawned on me after seeing an example I found elsewhere that > >>you don't call some module method to fetch the next user-entered line. > >> > >>You call the input() built-in. >

Re: Baffled by readline module

2023-03-09 Thread Grant Edwards
On 2023-03-09, Cameron Simpson wrote: > [...] >>It finally dawned on me after seeing an example I found elsewhere that >>you don't call some module method to fetch the next user-entered line. >> >>You call the input() built-in. > > Ah. That's not overtly stated? [...reads...] Ah, there it is in

Re: Baffled by readline module

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 09:01, Cameron Simpson wrote: > I think this might be the common case of a module which wraps another > library: there's a tension between describing everything in pointless > detail and the trite "we're just shimming this library, go read its > docs". Yeah, it's a

Re: Baffled by readline module

2023-03-09 Thread Cameron Simpson
On 09Mar2023 13:08, Grant Edwards wrote: On 2023-03-09, Chris Angelico wrote: Not sure about the history file, and I would assume that if you don't configure one, history is simply lost when you restart. But with tab completion, unless you need to be able to input a tab character, it should

Re: Baffled by readline module

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 08:10, Grant Edwards wrote: > What's really weird about the docs is that when it is described it > doesn't even _mention_ that it provides command-line recall and > editing: > > It just talks about manipulating history files and about > tab-completion of Python identfiers.

Re: Baffled by readline module

2023-03-09 Thread Grant Edwards
On 2023-03-09, Chris Angelico wrote: > Not sure about the history file, and I would assume that if you don't > configure one, history is simply lost when you restart. But with tab > completion, unless you need to be able to input a tab character, it > should be safe to ignore the feature and

Re: Baffled by readline module

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 06:28, Grant Edwards wrote: > > In an interactive command-line Python program on Linux, I want to be > able to read a line at a time from stdin, providing command line > history and editing to the user. In C, I would use GNU readline to do > that. > > Python has the

Re: Baffled by readline module

2023-03-09 Thread Grant Edwards
On 2023-03-09, Grant Edwards wrote: > In an interactive command-line Python program on Linux, I want to be > able to read a line at a time from stdin, providing command line > history and editing to the user. In C, I would use GNU readline to do > that. > > Python has the readline module, which

Baffled by readline module

2023-03-09 Thread Grant Edwards
In an interactive command-line Python program on Linux, I want to be able to read a line at a time from stdin, providing command line history and editing to the user. In C, I would use GNU readline to do that. Python has the readline module, which appears to be a wrapper for GNU readline.