On Fri, Nov 24, 2017 at 11:38 PM, Martin Alsinet <mar...@alsinet.com.ar>
wrote:

> Hello Charlie:
>
> I have found that I like better to use a combination of tangle and import
> instead of noweb syntax.
>
> #+BEGIN_SRC python :tangle board.py
> def init_board(args)
>     return [[-1 for x in range(3)] for y in range(3)]
> #+END_SRC
>
> #+BEGIN_SRC python
> import sys
> import os
> from board import init_board
>
> def main(args):
>     init_board(args)
>
> if __name__ == "__main__":
>     main(sys.argv)
> #+END_SRC
>
> Then, you do a *M-x org-babel-tangle* and org will write the first block
> into board.py. Then you go into the second block and run it with *C-c C-c* and
> it will load the init_board function from the tangled file.
>
> Writing it this way forces you to modularize your code blocks to be able
> to call them from other blocks and you can even build your whole
> application tangling the source blocks into files.
>
> The :noweb syntax seems to me to be a templating solution used for a code
> module problem.
>

It can be if you like that style. You can define re-usable and callable
source blocks and tangle them to their own file and to other files, too.
For example using the example above you can use both approaches:

#+NAME: init
#+BEGIN_SRC python :tangle board.py :comments no
def init_board(args)
    return [[-1 for x in range(3)] for y in range(3)]
#+END_SRC

#+NAME: org_gcr_2017-11-30_mara_1BB0EB7B-1693-458D-B1AD-CE44ED9961C1
#+BEGIN_SRC python :comments no :tangle program.py
import sys
import os

«init»

def main(args):
    init_board(args)

if __name__ == "__main__":
    main(sys.argv)
#+END_SRC

Calling `org-babel-expand-src-block'

Reply via email to