python - 更改 Python 交互提示 ">>>"

标签 python python-3.x command-line command-line-interface

我记得在 Python 3.5 文档中阅读过如何更改 Python 交互式提示上的 >>>,例如调用 help() 将如何更改它到 help>.

但由于某种原因,当我回去尝试内存时,我就是找不到它的说明。有谁知道这是否可能?

最佳答案

你没记错。

它在 sys 中模块(sys.ps1 & sys.ps2):

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 - 更改 Python 交互提示 ">>>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33683744/

相关文章:

python - 如何避免 Python 中日志文件臃肿?

Android 模拟器 - 命令行构建

php - 如何从命令行 PHP 写入文件?

python - 为什么在使用 python 调试器时没有定义异常对象?

python - 我不明白这个 Django 文档。我该如何使用这个模块?

Java - 运行Python脚本并监视连续输出

python - y, _ assignment 在 python/sklearn 中做什么?

python - 如何对列表进行切片以在新列表中获取列表的每 2 个连续元素?

python - 如何从 Python 调用 Postgres 11 存储过程

java - 使用空格在 Java 中创建新的 Firefox 配置文件?