By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

Gripe: Use Ctrl-D (i.e. EOF) to exit

P: n/a
<vent> I see there has been traffic over the years on this gripe, so just
let me vent my frustration, and add another reason why 'exit' (or possibly
exit() or quit() or halt() or some such) should exit Python, rather than
giving the ridiculous msg

Use Ctrl-D (i.e. EOF) to exit.

The additional reason is that God intended Ctrl-D to be "scroll down", as in
vi. I have my keyboard translator set up to do something very much like
that (actually, I translate ^D into a sequence of "cursor downs"), and
hitting the Ctrl-D key therefore does not drop me out of Python. More
generally, it is probably not uncommon for someone to translate ^D into
something else, using xmodmap or some such. I need to kill the entire
X-terminal to stop Python.

Now, if you're using a gui Python, there's probably a menu command you can
use to drop out. But if you're using the command-line version (e.g. the one
in CygWin) from a shell prompt, then you're out of luck.

Why isn't there a command or function to drop out of Python??!! Obviously
Python is clever enough to know that you want to exit when you type 'exit';
why does it make you stand on your head to do so?

Aaargh!

</vent>

Mike Maxwell


Jul 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Mike Maxwell wrote:

<vent> I see there has been traffic over the years on this gripe, so just
let me vent my frustration, and add another reason why 'exit' (or possibly
exit() or quit() or halt() or some such) should exit Python, rather than
giving the ridiculous msg

Use Ctrl-D (i.e. EOF) to exit.

The additional reason is that God intended Ctrl-D to be "scroll down", as in
vi.


Interesting... so God didn't write the ASCII standard, obviously:

ctrl-D 4 EOT END OF TRANSMISSION
A transmission control character used to indicate the conclusion of the transmission of one or more texts..

(From http://www.cs.tut.fi/~jkorpela/chars/c0.html, for example.)
Why anyone would think that ought to be translated as "down" rather than
"I'm done, bye" is unclear to me.

-Peter
Jul 18 '05 #2

P: n/a
Mike Maxwell wrote:
that (actually, I translate ^D into a sequence of "cursor downs"), and
hitting the Ctrl-D key therefore does not drop me out of Python. More
generally, it is probably not uncommon for someone to translate ^D into
something else, using xmodmap or some such. I need to kill the entire
X-terminal to stop Python.


How the hell do you send a EOF then, to the many other applications that
read from stdin until EOF? (such as most standard unix tools)

(Also see Peter's reply.)

--Irmen
Jul 18 '05 #3

P: n/a
On Mon, 23 Feb 2004 15:12:59 -0500, "Mike Maxwell"
<ma*****@ldc.upenn.edu> wrote:
The additional reason is that God intended Ctrl-D to be "scroll down", as in
vi.
Sorry God had decided that Ctrl-D was EOF long before vi was even
a bit pattern in Bill Joy's eye.

And of course if you are on the spawn of Satan, EOF is CTRL-Z and
thats how you exit Python...
use to drop out. But if you're using the command-line version (e.g. the one
in CygWin) from a shell prompt, then you're out of luck.


raise SystemExit

A wee bit longwinded I'll grant you, but it does the trick...

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
Jul 18 '05 #4

P: n/a
"Mike Maxwell" <ma*****@ldc.upenn.edu> writes:
Why isn't there a command or function to drop out of Python??!!


from sys import exit
exit()

--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
The *world* is arbitrary. *Individuals* are either fair
or unfair. Which are you? - Caulfield (Jef Mallett)
Jul 18 '05 #5

P: n/a
"Mike Maxwell" <ma*****@ldc.upenn.edu> writes:
<vent> I see there has been traffic over the years on this gripe, so just
let me vent my frustration, and add another reason why 'exit' (or possibly
exit() or quit() or halt() or some such) should exit Python, rather than
giving the ridiculous msg

Use Ctrl-D (i.e. EOF) to exit.


of course typing EOF is the normal way to tell any unix stdio app to
exit. but the EOF key depends on your tty settings and is set with
stty. hardcoding ctrl-d is strictly speaking broken ;)

-- erno
Jul 18 '05 #6

P: n/a
[Mark Jackson]
"Mike Maxwell" <ma*****@ldc.upenn.edu> writes:
Why isn't there a command or function to drop out of Python??!!

from sys import exit
exit()


Or maybe, a bit simpler:

raise SystemExit

One may also manage to merely fall to the end of your __main__ module.

--
François Pinard http://www.iro.umontreal.ca/~pinard

Jul 18 '05 #7

P: n/a
Peter Hansen wrote:
ctrl-D 4 EOT END OF TRANSMISSION
A transmission control character used to indicate the conclusion of
the transmission of one or more texts..

Why anyone would think that ought to be translated as "down" rather
than "I'm done, bye" is unclear to me.
To this and other comments along this line, I'll just add my own (not trying
to start a flame war, just explaining what may seem an odd choice on my
part):

IMHO, there's an unfortunate juxtaposition (I won't say confusion) of two
meanings of Ctrl-D: one is the ASCII char (as above), the other is whatever
is produced by pressing the 'd' key while the key labeled 'Ctrl' is pressed.

On Lisp Machines (and if you're too young to know what those were, you're
too young), there was a whole set of special purpose keys, including a Meta
key and a Hyper key. Their effect was similar to the Ctrl or Shift keys, in
that they modified the output of an "ordinary" key. Most keyboards nowadays
come with an Alt key, which could be used for what I want (move the cursor
down 7 rows, or scroll half a screen, or whatever), except that it has a
different function. And since there is no Meta or Hyper key on my keyboard,
I use the key to the left of the 'A' key (easy to reach both that and all
the alphabetic keys at the same time) as a key modifier, to do cursor
movement (^A = beginning of line, ^H = left one char, etc.). It happens
that that modifier key is labeled "Caps Lock" on most modern keyboards.
Under Linux, I can re-map it to a special modifier key, which does not then
interfere with using the Ctrl key to produce the Ascii control chars, so I
can use ^D to kill Python. But it's not so easy to re-map it under Windows,
and the only alternative seems to be to re-map it to be the Ctrl key. (And
don't say that I should just use Linux--the range of standardized cursor
movement keystrokes is _far_ greater under Windows than it is under Linux
environments that I've seen.)

So the upshot of it is, I want to have a keystroke to move down a half dozen
lines _much_ more often than I want one to exit a program. And my fingers
know Ctrl-d.

I might also point out that one can use other modifiers at the same time as
the Ctrl, e.g. Ctrl-Shift-D on my keyboard selects text for seven lines
down. There is obviously no Ascii equivalent of this, but it's a useful
keystroke.

Peter Hansen also wrote: Interesting... so God didn't write the ASCII standard, obviously


No, He used Hebrew. Duh. (I might also point out that the Hebrew alphabet,
lacking a case distinction, would fit nicely into a 6-bit encoding, as was
used on the CDC Cyber 170 that I wrote my dissertation on. You don't know
what a Cyber 170 is? You _are_ too young!)

Mike McSwell


Jul 18 '05 #8

P: n/a
* Erno Kuusela <er*******@erno.iki.fi> [2004-02-23 17:38]:

of course typing EOF is the normal way to tell any unix stdio app to
exit. but the EOF key depends on your tty settings and is set with
stty. hardcoding ctrl-d is strictly speaking broken ;)


I'm not sure if you were implying that python does this...

I just tested it, and it's not hardcoded (2.3a2 darwin).

lap:john$ stty eof ^A
lap:john$ cat
nthoeu
nthoeu
< exited by typing ^A >
lap:john$ python
Python 2.3a2+ (#4, Mar 2 2003, 17:13:46)
[GCC 3.1 20020420 (prerelease)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

< exited by typing ^A >
lap:john$

So, another solution to the OP's problem is to change the EOF character
to something else.

-John
< my_first_name AT my_last_name DOT net >

Jul 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.