Python and EOF

raf macports at raf.org
Sun Mar 28 00:33:13 UTC 2021


On Sat, Mar 27, 2021 at 09:03:37PM +0000, Richard Tobin <richard at inf.ed.ac.uk> wrote:

> 
> > > Is it possible to make python behave correctly when the user's EOF
> > > character is not set to control-D?  It works fine on Linux, but not
> > > with the macports on the Mac.
> > >
> > > For historical reasons I have control-Z as my EOF character.  But
> > > typing it in python results in it being suspended rather than
> > > exiting.  Typing control-D just echoes ^D.
> > >
> > > As I understand it, this is because python in macports uses libedit
> > > (aka editline) rather than readline.  Readline adjusts the key
> > > bindings to match the user's stty settings, but libedit doesn't.
> 
> > Are you sure it's Python? Ctrl-Z is the key for putting
> > the current process group into the background in shells
> > that support job-control. Maybe it's the shell doing
> > it.
> 
> Control-Z is the *default* suspend character, but it can be changed
> using stty.  I set suspend to control-X and EOF to control-Z, and I
> want Python to respect this, as other programs do.
> 
> That is, I want control-Z to act as EOF and quit Python, and I want
> control-X to suspend it.
> 
> Readline and editline use raw (or possibly cbreak) mode, so they have
> to simulate suspend and EOF thmselves.  Readline queries the suspend
> and EOF characters so that it can do the right thing; editline
> doesn't seem to.
> 
> -- Richard

That's annoying, but perhaps editline can be configured to do what you
need. It does have a config file described here:

  https://linux.die.net/man/5/editrc

There is a "setty" command which can set tty characters. It looks like
that should do it. Although it should default to getting the characters
from the terminal. Perhaps a bugreport for editline would be a good idea.
There seem to be multiple editlines. It might be one of these (probably the
first one):

  http://thrysoee.dk/editline/
  https://github.com/troglobit/editline

Only the first one has an ~/.editrc file, so hopefully, that's the one.

cheers,
raf



More information about the macports-users mailing list