emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: documenting python module examples in orgmode


From: John Kitchin
Subject: Re: documenting python module examples in orgmode
Date: Mon, 09 Dec 2019 09:19:40 -0500
User-agent: mu4e 1.3.4; emacs 26.1

The only way to do this is if you have an intermediate tangle step so
that the python file exists in a place where it can be imported. For
example, this small modification will make what you want happen.


#+NAME: my_module.py
#+begin_src python :tangle my_module.py
print('Importing my_module...')

test = 'Test String'

def find_index(to_search, target):
    '''Find the index of a value in a sequence'''
    for i, value in enumerate(to_search):
        if value == target:
            return i

    return -1
#+end_src

#+NAME: intro.py
#+begin_src python :var tangle=(org-babel-tangle)
import my_module

courses = [ 'History', 'Math', 'Geography', 'Science' ]
#+end_src

#+RESULTS: intro.py
: Importing my_module...



Divan Santana <address@hidden> writes:

> Hi All,
>
> I'm trying to document python module examples in orgmode.
>
> I'm sure this is possible, but not quite sure how to do it.
>
> I'd like to define the python module in one block, and then import it in
> another.
>
> #+NAME: my_module.py
> #+begin_src python
> print('Importing my_module...')
>
> test = 'Test String'
>
> def find_index(to_search, target):
>     '''Find the index of a value in a sequence'''
>     for i, value in enumerate(to_search):
>         if value == target:
>             return i
>
>     return -1
> #+end_src
>
> #+NAME: intro.py
> #+begin_src python
> import my_module
>
> courses = [ 'History', 'Math', 'Geography', 'Science' ]
> #+end_src
>
> How can one do this?
>
> Thanks very much.


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]