问题
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