how to show current directory in ipython prompt

风流意气都作罢 提交于 2019-12-05 21:26:22

问题


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

Instead of this:
In [1]:

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

回答1:


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} >>>"




回答2:


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

In [8]: import os

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

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



回答3:


Using ! before pwd will show the current directory

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.



来源:https://stackoverflow.com/questions/38481506/how-to-show-current-directory-in-ipython-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!