如何在ipython promp中显示当前目录

2024-04-24 17:22:57 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法在IPython提示符中显示当前目录?

Instead of this:
In [1]:

Something like this:
In<~/user/src/proj1>[1]:

Tags: ofinsrcipythonthissomethinglike提示符
3条回答

https://ipython.org/ipython-doc/3/config/details.html#specific-config-details

In the terminal, the format of the input and output prompts can be customised. This does not currently affect other frontends.

因此,在.ipython/profile_default/ipython_config.py中,输入如下内容: c.PromptManager.in_template = "In<{cwd} >>>"

使用!在pwd显示当前目录之前

In[1]: !pwd
/User/home/

当交互计算时,通常需要访问底层shell。这是可以通过使用感叹号!(或砰)在一行开始时执行一个命令。

您可以使用os.getcwd(当前工作目录)或本机操作系统命令pwd

In [8]: import os

In [9]: os.getcwd()
Out[9]: '/home/rockwool'

In [10]: pwd
Out[10]: '/home/rockwool'

相关问题 更多 >