From mboxrd@z Thu Jan 1 00:00:00 1970 From: Emmanuel Charpentier Subject: Possible proble with Python block edition, or pilot error ? Date: Tue, 05 Mar 2019 23:18:40 +0100 Message-ID: <4fe8cca2b504c8d6154a49ace63fabb5e8601def.camel@free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([209.51.188.92]:50132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1IOt-0000uA-KJ for emacs-orgmode@gnu.org; Tue, 05 Mar 2019 17:19:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1IOr-0002OS-4Z for emacs-orgmode@gnu.org; Tue, 05 Mar 2019 17:19:02 -0500 Received: from smtp1-g21.free.fr ([212.27.42.1]:35508) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1IOo-0002BK-5R for emacs-orgmode@gnu.org; Tue, 05 Mar 2019 17:19:00 -0500 Received: from zen-book-flip (unknown [82.228.67.28]) (Authenticated sender: emm.charpentier) by smtp1-g21.free.fr (Postfix) with ESMTPSA id 92AB6B00548 for ; Tue, 5 Mar 2019 23:18:40 +0100 (CET) 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: org-mode-email The following python snippet does execute normally from a Python (2.7) temporary buffer Source : ========================================= print "Start of block called from a Python temporary buffer" print NomDeFichier try: FN=NomDeFichier except: FN="Chose.txt" finally: print FN print "**"+FN+"**" print "End of block called from a Python temporary buffer" ========================================= Execution result: ========================================= >>> Start of block called from a Python temporary buffer Bidule.txt Bidule.txt **Bidule.txt** End of block called from a Python temporary buffer >>> Start of block called from a Python temporary buffer Bidule.txt Bidule.txt **Bidule.txt** End of block called from a Python temporary buffer ========================================= But the following Babel Python block, from which the previous snippet derives, fails to run : Block : ========================================= #+begin_src python :var NomDeFichier="Bidule.txt" :exports both :results file :preamble "# -*- coding: utf-8 -*-" print "Start of block called from an Org Python block" print NomDeFichier try: FN=NomDeFichier except: FN="Chose.txt" finally: print FN # Irrelevant for now: # F1=file(FN,"w") # F1.write("Tagada\n") # F1.write("tsoin-tsoin...\n") # F1.close() print "End of block called from an Org Python block" # Kept to pacify Org... FN #+end_src ========================================= Execution result : ========================================= >>> print "Start of block called from an Org Python block" Start of block called from an Org Python block >>> print NomDeFichier Bidule.txt >>> try: ... FN=NomDeFichier ... File "", line 3 ^ SyntaxError: invalid syntax >>> except: File "", line 1 except: ^ SyntaxError: invalid syntax >>> FN="Chose.txt" File "", line 1 FN="Chose.txt" ^ IndentationError: unexpected indent >>> >>> finally: File "", line 1 finally: ^ SyntaxError: invalid syntax >>> print FN File "", line 1 print FN ^ IndentationError: unexpected indent >>> >>> # Irrelevant for now: ... # F1=file(FN,"w") ... # F1.write("Tagada\n") ... # F1.write("tsoin-tsoin...\n") ... # F1.close() ... print "End of block called from an Org Python block" End of block called from an Org Python block >>> # Kept to pacify Org... ... FN 'Bidule.txt' >>> >>> open('/tmp/babel-2gEcoQ/python-r1nkjR', 'w').write(str(_)) >>> >>> >>> 'org_babel_python_eoe' 'org_babel_python_eoe' >>> ========================================= Possibly relevant : from (packages-list-packages) : python-mode 20181223.1933 installed Python major mode Also posibly relevant : a very similar Sage block, whose edit mode is sage-shell-mode, runs without problem. I'm lost. Suggestions ? -- Emmanuel Charpentier