小编pjc*_*c42的帖子

将工作目录设置为Notebook目录

在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文件方法?

python ipython ipython-notebook

6
推荐指数
1
解决办法
2725
查看次数

标签 统计

ipython ×1

ipython-notebook ×1

python ×1