From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: documenting python module examples in orgmode Date: Mon, 09 Dec 2019 09:19:40 -0500 Message-ID: References: <87k175dbr1.fsf@santanas.co.za> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:36688) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ieJt4-0004Ed-A8 for emacs-orgmode@gnu.org; Mon, 09 Dec 2019 09:19:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ieJt3-00040G-2C for emacs-orgmode@gnu.org; Mon, 09 Dec 2019 09:19:46 -0500 Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]:36105) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ieJt2-0003zz-S6 for emacs-orgmode@gnu.org; Mon, 09 Dec 2019 09:19:45 -0500 Received: by mail-qv1-xf2e.google.com with SMTP id b18so2690787qvy.3 for ; Mon, 09 Dec 2019 06:19:43 -0800 (PST) Received: from LAPTOP-8C07ES6L.wv.cc.cmu.edu (LAPTOP-8C07ES6L.wv.cc.cmu.edu. [128.237.195.56]) by smtp.gmail.com with ESMTPSA id q34sm8802268qtc.33.2019.12.09.06.19.41 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Dec 2019 06:19:41 -0800 (PST) In-reply-to: <87k175dbr1.fsf@santanas.co.za> 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: emacs-orgmode@gnu.org 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 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