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

boB Stepp robertvstepp at gmail.com
Sat Mar 12 01:46:38 EST 2016


On Fri, Mar 11, 2016 at 11:02 PM, Cameron Simpson <cs at zip.com.au> wrote:
> 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.

Win7-64bit, Py 3.5.1

[...]

>  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?)

I did with the non-printing control character, but not with '\u25ba' !
 So I had to go through some contortions after some research to get my
Win7 cmd.exe and PowerShell to display the desired prompt using
'\u25ba' as the character with utf-8 encoding.  My new
pythonstartup.py file (Which PYTHONSTARTUP now points to) follows:

#!/usr/bin/env python3

import os
import sys

os.system('chcp 65001')    # cmd.exe and PowerShell require the code
page to be changed.
sys.ps1 = '\u25ba '  # I remembered to add the additional space.

Additionally, one must set the font for cmd.exe and PowerShell to
"Lucida Console" or the above will not work.

> 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.

So let's see if this copies and pastes into a plain text Gmail and is
visible to "many environments":

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.
Active code page: 65001
► print("Can everyone read the prompt?")
Can everyone read the prompt?
►

It looks good to me in Gmail.  Any issues?  Angry users of pure ASCII
terminals? ~(:>)

I still have not figured out how to make this change in IDLE.
Research will continue...

-- 
boB


More information about the Tutor mailing list