2013-04-21 21 views
2

如果我用这个块org-mode babel python会话和内联图像不兼容?

#+BEGIN_SRC python :results file 
from pylab import * 
plot(rand(10)) 
savefig('images/test.png') 
return 'images/test.png' 
#+END_SRC 

然后将结果块显示我的阴谋的内联版本。

如果现在我切换到该块

#+BEGIN_SRC python :session test :results file 
from pylab import * 
plot(rand(10)) 
savefig('images/test.png') 
return 'images/test.png' 
#+END_SRC 

然后将结果块不显示内联的情节,但这

| <matplotlib.lines.Line2D | object | at | 0x35c0650> | 

使用会话是一种强制性的我,因为我需要几个块共享变量。

我的方法有什么明显的错误吗?

回答

1

根据org-mode documentation,如果代码在会话中运行,则必须删除return

#+BEGIN_SRC python :session test :results file 
    from pylab import * 
    plot(rand(10)) 
    savefig('images/test.png') 
    'images/test.png' 
#+END_SRC 

#+RESULTS: 
[[file:images/test.png]] 

因为“返回的结果是由解释器执行的最后评估的结果”。