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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38481506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:02:19  来源:igfitidea点击:

how to show current directory in ipython prompt

pythonipythonprompt

提问by motam79

Is there is way to show the current directory in IPython prompt?

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

Instead of this:
In [1]:

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

采纳答案by Arjen Dijkstra

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

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.

在终端中,可以自定义输入输出提示的格式。这目前不会影响其他前端。

So, in .ipython/profile_default/ipython_config.py, put something like: c.PromptManager.in_template = "In<{cwd} >>>"

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

回答by DurgaDatta

You can use os.getcwd(current working directory) or in the native os command pwd.

您可以使用os.getcwd(current working directory) 或在本机 os 命令中pwd

In [8]: import os

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

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

回答by David Miller

Using ! before pwd will show the current directory

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

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

When interactive computing it is common to need to access the underlying shell. This is doable through the use of the exclamation mark ! (or bang) To execute a command when present in beginning of line.

在交互式计算时,通常需要访问底层 shell。这可以通过使用感叹号来实现!(或 bang)当出现在行首时执行命令。