更改Python交互式提示“>>>” [英] Change Python interactive prompt ">>>"

查看:81
本文介绍了更改Python交互式提示“>>>”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,一旦弄清楚了,我可能最终将其删除,但是我发誓我记得在Python 3.5文档中阅读了如何更改>。 >> 在Python交互式提示上,例如调用 help()如何将其更改为 help> 。但是由于某种原因,当我再次尝试并记住时,我只是找不到相应的说明。有人知道这是否可能吗?还是我只是在想象事情?

This is probably a silly question, and I'll probably end up deleting it once I figure it out, but I swear I recall reading, in the Python 3.5 docs, how to change the >>> on the Python interactive prompt, such as how calling help() will change it to help>. But for some reason, when I've gone back to try and remember, I just can't find the instructions to it. Does anyone know if this is possible, or am I just imagining things?

谢谢

推荐答案

您没记错。

它在 sys 模块(sys.ps1和sys.ps2):

It's in the sys module (sys.ps1 & sys.ps2):


指定解释程序的主提示和辅助提示的字符串。仅当解释器处于交互模式时才定义它们。在这种情况下,它们的初始值为 >>>和 ...。如果将非字符串对象分配给任一变量,则每次解释器准备读取新的交互式命令时,都会重新评估其str();

Strings specifying the primary and secondary prompt of the interpreter. These are only defined if the interpreter is in interactive mode. Their initial values in this case are '>>> ' and '... '. If a non-string object is assigned to either variable, its str() is re-evaluated each time the interpreter prepares to read a new interactive command; this can be used to implement a dynamic prompt.

例如:


   >>> import sys
   >>> sys.ps1 = "3.5>>> "
   3.5>>> sys.ps2 = "3.5... "
   3.5>>>

这篇关于更改Python交互式提示“>>>”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆