Make the source code from one code block the input to another code block in Emacs org-mode

泄露秘密 提交于 2019-12-05 01:31:49

If you have set up emacs/org-mode so that python code is enabled ((python . t) in org-babel-do-load-languages), you are almost there, I changed your example to

#+NAME: basic_query 
#+BEGIN_SRC SQL 
  SELECT name, grade FROM students 
#+END_SRC 

#+BEGIN_SRC python :export results :noweb yes :tangle yes
import sql_helper 
query = """
    <<basic_query>>
    """
query_status = sql_helper.run_query(query)  

#+END_SRC 

My python is a little rusty, but at least if I tangle this to

import sql_helper 
query = """
    SELECT name, grade FROM students 

    """
query_status = sql_helper.run_query(query)

python does no longer complain about the syntax, but about the missing module sql_helper...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!