From: Sebastian Miele <sebastian.miele@gmail.com>
To: Ken Mankoff <mankoff@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: noweb and :var statements
Date: Sun, 06 Oct 2019 20:55:16 +0000 [thread overview]
Message-ID: <87h84liogb.fsf@gmail.com> (raw)
In-Reply-To: <87imp1fxnl.fsf@gmail.com>
Ken Mankoff <mankoff@gmail.com> 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
> <<setup>>
> print(foo)
> #+END_SRC
>
>
> And now I can hide <<setup>> 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
> <<setup(table="foo_data" varname="foo")>>
> <<setup(table="bar_data" varname="bar")>>
> #+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 <<setup>> 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.
prev parent reply other threads:[~2019-10-06 20:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-06 16:33 noweb and :var statements Ken Mankoff
2019-10-06 19:39 ` Sebastian Miele
2019-10-06 19:52 ` Sebastian Miele
2019-10-06 20:08 ` Ken Mankoff
2019-10-06 21:08 ` Sebastian Miele
2019-10-06 21:17 ` Sebastian Miele
2019-10-07 5:18 ` Ken Mankoff
2019-10-07 9:22 ` Sebastian Miele
2019-10-06 20:05 ` Ken Mankoff
2019-10-06 20:55 ` Sebastian Miele [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h84liogb.fsf@gmail.com \
--to=sebastian.miele@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=mankoff@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).