在IPython中,是否可以通过编程方式将工作目录设置为笔记本的目录?
例如,以下代码将在常规.py文件中工作.
import os
# show working dir
os.chdir(os.path.abspath('/'))
print "initial working directory:\t", os.getcwd()
# get path of script file
scriptPath = os.path.abspath(os.path.dirname(__file__))
# change working dir to dir with script file
os.chdir(scriptPath)
# show working directory
print "final working directory:\t", os.getcwd()
Run Code Online (Sandbox Code Playgroud)
但是,我找不到相当于的
__file__
Run Code Online (Sandbox Code Playgroud)
ipython nb文件的变量.是否有一些等效的ipynb文件方法?