Baffled by readline module
Grant Edwards
grant.b.edwards at gmail.com
Thu Mar 9 22:11:56 EST 2023
On 2023-03-10, 2QdxY4RzWzUUiLuE at potatochowder.com <2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
> On 2023-03-10 at 12:57:48 +1100,
> Chris Angelico <rosuav at gmail.com> wrote:
>
>> On Fri, 10 Mar 2023 at 12:56, Greg Ewing via Python-list
>> <python-list at python.org> 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 MacOSX I can use up arrow with input()
>> > to recall stuff I've typed before, without having to
>> > import anything.
If you run this application from the command line, you get command
recall and editing when entering strings at the "cmd:" prompt?
#!/usr/bin/python
while True:
try:
line = input('cmd: ')
except EOFError:
print()
break
print('You entered "%s"' % line)
>> import sys; "readline" in sys.modules
>>
>> Is it? Might be that something's pre-importing it.
>
> My ~/.pythonrc contains the following:
>
> import readline
> import rlcompleter
> readline.parse_and_bind( 'tab: complete' )
>
> IIRC, that's been there "forever," certainly back into Python2, and
> probably back into Python1. On my Arch Linux system Python 3.10.9, I
> get readline behavior with or without those lines.
I "get readline behavior" in the REPL without an "import readline",
but that's irrelevent. We're talking about a command-line
application that's calling input().
More information about the Python-list
mailing list