From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Need control over insertion point of variables in code blocks Date: Fri, 22 Jul 2011 09:34:03 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=00235452ffec5bc25704a8a37d8f Return-path: Received: from eggs.gnu.org ([140.186.70.92]:53961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkAFJ-0005kF-IR for emacs-orgmode@gnu.org; Fri, 22 Jul 2011 03:34:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QkAFI-0005dr-4l for emacs-orgmode@gnu.org; Fri, 22 Jul 2011 03:34:05 -0400 Received: from mail-qw0-f41.google.com ([209.85.216.41]:48195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkAFI-0005dW-1Q for emacs-orgmode@gnu.org; Fri, 22 Jul 2011 03:34:04 -0400 Received: by qwa26 with SMTP id 26so1329993qwa.0 for ; Fri, 22 Jul 2011 00:34:03 -0700 (PDT) In-Reply-To: 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dirk Scharff Cc: Org mailing list --00235452ffec5bc25704a8a37d8f Content-Type: text/plain; charset=ISO-8859-1 On Fri, Jul 22, 2011 at 9:22 AM, Dirk Scharff wrote: > Hi > > i just noticed that variables are assigned in the top of the exported code. > That can be problematic in some situations: > > #+source: the_test > #+begin_src python :var x=3 :tangle test.py :results output > from __future__ import division > print x > #+end_src > > > tangling results in: > > x=3 > from __future__ import division > print x > > The problem with the result is simple: > SyntaxError: from __future__ imports must occur at the beginning of the > file > > To export this correctly I'd need the possibility to tell org-mode where > the variables are supposed to be inserted. Is there a way to do this? I > didn't find a keyword for this in the documentation. > For tangling: you could put from __future__ imports into the :shebang and use padline ":padline no", i.e.: #+source: the_test #+begin_src python :var x=3 :tangle test.py :results output :shebang from __future__ imports :padline no print x #+end_src which results in from __future__ imports print x Keep in mind, that I have NEVER used python (although I should...). Cheers, Rainer > A second problem I have at the moment lies with the execution of > source-blocks in tables. What I'd like to do: > > | argument | result | > | 1 | #ERROR | > | | | > #+TBLFM: $2=call_the_test(x=$<) > > I guess I'm just doing something wrong here. Executing the #+Tblfm results > in the error: "reference $< not found in buffer". How do I do the reference > correctly in this case? > > You can test both cases in the attached org-file. > > > > > > -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax (F): +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug --00235452ffec5bc25704a8a37d8f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Fri, Jul 22, 2011 at 9:22 AM, Dirk Sc= harff <= dirk.scharff@googlemail.com> wrote:
Hi

i just noticed that variables are assigned in the top of the exported code.= That can be problematic in some situations:

#+source: the_test
#+begin_src python :var x=3D3 :tangle test.py :results output
from __future__ import division
print x
#+end_src


tangling results in:

x=3D3
from __future__ import division
print x

The problem with the result is simple:
SyntaxError: from __future__ imports must occur at the beginning of the fil= e

To export this correctly I'd need the possibility to tell org-mode wher= e the variables are supposed to be inserted. Is there a way to do this? I d= idn't find a keyword for this in the documentation.

For tangling: you could put =A0=A0from __future__ impor= ts into the :shebang and use padline ":padline no", i.e.:

#+source: the_test
#+begin_src python :var= x=3D3 :tangle test.py :results output :shebang from __future__ imports :pa= dline no
print x
#+end_src

which resul= ts in

from __future__ imports
print= x

Keep in mind, that I have NEVER used pyth= on (although I should...).

Cheers,

Rainer
=A0
A second problem I have at the moment lies with the execution of source-blo= cks in tables. What I'd like to do:

| argument | result |
| =A0 =A0 =A0 =A01 | #ERROR |
| =A0 =A0 =A0 =A0 =A0| =A0 =A0 =A0 =A0|
#+TBLFM: $2=3Dcall_the_test(x=3D$<)

I guess I'm just doing something wrong here. Executing the #+Tblfm resu= lts in the error: "reference $< not found in buffer". How do I= do the reference correctly in this case?

You can test both cases in the attached org-file.








--
Rainer M. Krug, PhD= (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. = (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch = University
South Africa

Tel : =A0 =A0 =A0 +33 - (0)9 53 10 27 44
Cell: =A0 = =A0 =A0 +33 - (0)6 85 62 59 98
Fax (F): =A0 =A0 =A0 +33 - (0)9 58 10 27 = 44

Fax (D): =A0 =A0+49 - (0)3 21 21 25 22 44

email: =A0 =A0 = =A0Rainer@krugs.de=

Skype: =A0 =A0 =A0RMkrug

--00235452ffec5bc25704a8a37d8f--