将参数(目录)传递给 ipython 笔记本中的 %cd 命令

Passing parameter (directory) to %cd command in ipython notebook

我正在尝试将参数(目录)传递给 ipython 笔记本中的 %cd 命令,如下所示:

 rootdir = "D:\mydoc"
 %cd rootdir

但我收到以下错误:

 [Error 2] The system cannot find the file specified: u'rootdir'
 D:\mydoc

当我在做的时候

 %cd D:\mydoc

这显然有效,但我希望能够使用参数指定我的工作目录...

非常感谢谁能帮助我。

祝福

您可以使用 $ 来使用变量中的值。

%cd $rootdir