From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Miele Subject: Re: noweb and :var statements Date: Sun, 06 Oct 2019 20:55:16 +0000 Message-ID: <87h84liogb.fsf@gmail.com> References: <87k19hg7g1.fsf@gmail.com> <87k19hirz7.fsf@gmail.com> <87imp1fxnl.fsf@gmail.com> Reply-To: sebastian.miele@gmail.com Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:37428) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHDYq-0000q1-6y for emacs-orgmode@gnu.org; Sun, 06 Oct 2019 16:55:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHDYp-0003W3-2b for emacs-orgmode@gnu.org; Sun, 06 Oct 2019 16:55:24 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:50689) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHDYo-0003UI-6Y for emacs-orgmode@gnu.org; Sun, 06 Oct 2019 16:55:22 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5so10480034wmg.0 for ; Sun, 06 Oct 2019 13:55:21 -0700 (PDT) In-reply-to: <87imp1fxnl.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: Ken Mankoff Cc: emacs-orgmode@gnu.org Ken Mankoff writes: > Hi Sebastian, > > I'm not getting the results I expect from your MWE either. Perhaps I > gave too much code and asked X when what I really want is Y. I think > I've distilled it to this: > > What is the most elegant Org way to get a table into a Python array? I do not know whether it is the most elegant way, but the following works, and probably is at least close to shortes possible way: #+NAME: table_foo | foo | |-----| | 42 | | 100 | #+BEGIN_SRC python :var table=table_foo :tangle table.py #+END_SRC After tangling, table.py contains "table=[[42], [100]]". Did you know that you can have several source code blocks tangling to the same file? Maybe you do not really need noweb stuff at all. If you add a second block, e.g. #+BEGIN_SRC python :tangle table.py mangle_table #+END_SRC then, after tangling, table.py contains "table=[[42], [100]]" and "mangle_table". > I can code it directly: > > #+BEGIN_SRC python > <> > print(foo) > #+END_SRC > > > And now I can hide <> in a section at the bottom of the > document. If it looks like this, everything works: > > #+NAME: setup > #+BEGIN_SRC python > foo = np.array([42,43,44]) > #+END_SRC > > But is there a more elegant method? Can I get the same behavior if the > data I want is in an Org table rather than hard-coded directly in > Python? This use-case is covered by what I wrote above. You can put the named Org table at the bottom of the file. Another note: You can tangle to different files from one Org file. You may e.g. add an additional source block: #+BEGIN_SRC python :tangle use_table.py include_table_py use_table #+END_SRC where include_table_py must be replaced by the Python way of saying: include the file table.py. (I do not know Python.) > Ideally, I'd like to have: > > #+NAME: setup > #+BEGIN_SRC python > <> > <> > #+END_SRC > > And a #+NAME: setup block that takes a :var table and sticks it in the > :var varname variable. I strongly suspect that you do not really need noweb stuff and still struggle to understand the very basics of tangling. > And then after calling <> be able to use variable "foo" and > "bar" that are generated from column or 2D Org tables elsewhere in the > document. Can I do this in Org? > > Thanks, > > -k.