Skip to main content
 首页 » 编程设计

python之木星 : Arguments in line magic commands

2024年10月01日14kenshinobiy

我经常使用Jupyter的cell magic命令

%%px --targets 3 
#Some code 

在 3 号簇上运行一些代码。使用 line 魔术命令获得相同结果的语法是什么?

我试过了

%px --targets 3 #Some code 

但是没用

请您参考如下方法:

(未测试)您可以将后缀与集群编号 3 相关联,如此处所述 https://ipython.org/ipython-doc/3/parallel/magics.html#multiple-active-views

所以假设你的 IPython.parallel.Client 实例被称为 rc

c3 = rc[3] 
c3.activate('_3') 
c3.block = True 

然后你就可以写了

%px_3 #some code 

对于线魔术和

%%px_3  
#some code 

细胞魔法。