Python控制台名称自定义

发布于 2024-09-14 15:37:04 字数 150 浏览 5 评论 0原文

通常Python控制台看起来像这样:

>>> command

有没有办法让它看起来像这样:

SomeText>>> command

Usually the Python console looks like this:

>>> command

Is there a way to make it look like:

SomeText>>> command

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放手` 2024-09-21 15:37:04
sys.ps1 == ">>>"
sys.ps2 == "..."

您还可以在 PYTHONSTARTUP 环境变量中更改此设置。

例如(这不安全),将以下内容放入脚本中的某个位置并将 PYTHONSTARTUP 设置为指向该脚本。

import sys
import getpass
sys.ps1  = getpass.getuser( ) + ">>> "

当然,您可以将上面的最后一行更改为您想要的任何内容。

sys.ps1 == ">>>"
sys.ps2 == "..."

You can also change this in the PYTHONSTARTUP environment variable.

For example (this is not secure), put the following in a script somewhere and set PYTHONSTARTUP to point at that script.

import sys
import getpass
sys.ps1  = getpass.getuser( ) + ">>> "

Of course, you could change the last line above to anything you want.

时光瘦了 2024-09-21 15:37:04

您可以尝试

import sys
import os

sys.ps1 = os.getenv("USER") + sys.ps1

(或按照其他答案的建议使用getpass.getuser()

在更正后的版本中,当然更容易:

import sys
sys.ps1 = "SomeText" + sys.ps1

You could try

import sys
import os

sys.ps1 = os.getenv("USER") + sys.ps1

(or getpass.getuser() as suggested by the other answer)

In the corrected version, it's even easier, of course:

import sys
sys.ps1 = "SomeText" + sys.ps1
于我来说 2024-09-21 15:37:04

IPython 提供了设置复杂提示的便捷方法,如此处

IPython provides convenient way of setting sophisticated prompts as described here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文