emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Possible proble with Python block edition, or pilot error ?
@ 2019-03-05 22:18 Emmanuel Charpentier
  0 siblings, 0 replies; only message in thread
From: Emmanuel Charpentier @ 2019-03-05 22:18 UTC (permalink / raw)
  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 "<stdin>", line 3
    
    ^
SyntaxError: invalid syntax
>>> except:
  File "<stdin>", line 1
    except:
         ^
SyntaxError: invalid syntax
>>>     FN="Chose.txt"
  File "<stdin>", line 1
    FN="Chose.txt"
    ^
IndentationError: unexpected indent
>>> 
>>> finally:
  File "<stdin>", line 1
    finally:
          ^
SyntaxError: invalid syntax
>>>     print FN
  File "<stdin>", 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-03-05 22:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-05 22:18 Possible proble with Python block edition, or pilot error ? Emmanuel Charpentier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).