[Tutor] Changing the interpreter prompt symbol from ">>>" to ???

Cameron Simpson cs at zip.com.au
Sat Mar 12 00:02:21 EST 2016


On 11Mar2016 21:31, boB Stepp <robertvstepp at gmail.com> wrote:
>I must be bored tonight.  I have to confess that when copying and
>pasting from the interpreter into a plain text email, I often find it
>cluttered to confusing by all the ">>>..." that can result from nested
>quoting.  So I poked around on the Internet and found that I can
>temporarily change the prompt symbol using sys.ps1.  My initial trials
>are:
>
>Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900
>64 bit (AMD64)] on win32
>Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.ps1 = '=>'
>=>sys.ps1 = chr(26)
>→sys.ps1 = chr(16)
>>
>I personally like the last of these.  My question is, will this show
>up as a black, filled-in arrowhead pointing to the right on everyone's
>email?  I have yet to delve into Unicode display issues, but I have
>vague recollections that the old ASCII table values might not always
>display the same thing from one person's display to another one's.  Is
>this correct?

For 16 and 26, yes. They are not printable characters; I'm surprised they 
render as visible symbols at all. Certainly other terminals are under no 
obligation to render them this way.

When I run your code above I get empty appearing prompts as I would have 
expected - these are control characters and not printable.

This leads me to ask: what is your environment? Mine is Mac OSX in an iTerm, 
which renders Unicode.

Interestingly, your _email_ showing your code is presented to me as 
right-pointing triangle for chr(16) and a little arrow for chr(26), so your 
environment has translated your cut/paste from your display into something that 
renders. Your email message, as received here, is in UTF-8.

Decoding that Unicode says your right-arrow is codepoint 0x2192 and your 
triangle is 0x25ba. Let's write a little program:

  #!/usr/bin/python3
  import sys
  import unicodedata
  s=sys.stdin.read()
  for c in s:
    try:
      uname = unicodedata.name(c)
    except ValueError as e:
      uname = "UNNAMED: %s" % (e,)
    print("0x%04x %s" % (ord(c), uname))

Echoing your text into it says, for the right arrow and the triangle 
respectively:

  0x2192 RIGHTWARDS ARROW
  0x25ba BLACK RIGHT-POINTING POINTER

So it seems that your environment has chosen to transcribe your chr(26) and 
chr(16) into some glyphs for display, and matched those glyphs with suitable 
Unicode codepoints. (Well, "suitable" if you also see a right-arrow and a right 
pointing triangle; do you?)

So: I would not rely on your stuff being presented nicely if you use 16 and 26 
because they are not printable to start with, and you just got lucky. If, OTOH, 
you figure out some nice glyphs and their Unicode points, then many 
environments will render them sensibly. Though, of course, not a pure ACII 
terminal - those are rare these days though.

Finally, I would also recommend that whatever prompt you use has a trailing 
space so that people can more easily separate it from the code.


More information about the Tutor mailing list