From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ken Mankoff Subject: Re: noweb and :var statements Date: Mon, 07 Oct 2019 07:18:48 +0200 Message-ID: <87d0f9f807.fsf@gmail.com> References: <87k19hg7g1.fsf@gmail.com> <87k19hirz7.fsf@gmail.com> <87imp1irdr.fsf@gmail.com> <87ftk5fxi5.fsf@gmail.com> <87ftk5inu4.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:57774) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHLQ5-0001ot-F9 for emacs-orgmode@gnu.org; Mon, 07 Oct 2019 01:18:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHLQ4-00034H-CV for emacs-orgmode@gnu.org; Mon, 07 Oct 2019 01:18:53 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:41336) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHLQ4-00033P-5Q for emacs-orgmode@gnu.org; Mon, 07 Oct 2019 01:18:52 -0400 Received: by mail-lf1-x136.google.com with SMTP id r2so8259382lfn.8 for ; Sun, 06 Oct 2019 22:18:52 -0700 (PDT) In-reply-to: <87ftk5inu4.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: sebastian.miele@gmail.com Cc: emacs-orgmode@gnu.org Hi Sebastian, Thanks for your help. I was running with "-Q" but must have been making some other mistakes. It does work. As for your other email... I do know several tangles can go to the same file. And I may be using <> incorrectly, but I'm using it for the following reasons: 1) I'd like to bury code that must run first but is inconsequential at the bottom of the Org file. Noweb lets me have a tangled <> at the top, and then hide the lengthy <> code elsewhere. Is this a correct use case? 2) I'd like to import 10 tables, so I thought a noweb function might be useful for code reuse. I finally got the behavior I'm looking for. What I need to remember/understand is that <> just pastes the body, and <> evaluates the function. From this, my Python code needs to generate Python code! I now have the following MWE that behaves as I want both for in-buffer C-c C-c eval of main code block and tangled results. The key bit of code is the last babel block. Thanks for your help, -k. * MWE init #+BEGIN_SRC emacs-lisp :results output (setq org-confirm-babel-evaluate nil) (org-babel-do-load-languages 'org-babel-load-languages '((python . t))) (print (emacs-version)) (print (org-version nil t)) (org-babel-tangle) #+END_SRC * Main Project #+NAME: main #+BEGIN_SRC python :tangle MWE3.py :noweb yes :results output <> print(t42.sum()) print(t100.sum()) #+END_SRC #+RESULTS: main : 84.0 : 100.0 * Data Tables #+NAME: table_42 | foo | |-----| | 42 | | 42 | #+NAME: table_100 | bar | |-----| | 100 | * Setup #+NAME: setup #+BEGIN_SRC python :noweb yes import numpy as np <> <> #+END_SRC * Table Import Code #+NAME: import_table_to_varname #+BEGIN_SRC python :var table=table_42 :var varname="foo" :noweb yes :results output print(varname + "=np.array(" + str(table) + ").astype(np.float).flatten()") #+END_SRC