emacs-orgmode
[Top][All Lists]
Advanced

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

[O] Possible proble with Python block edition, or pilot error ?


From: Emmanuel Charpentier
Subject: [O] Possible proble with Python block edition, or pilot error ?
Date: Tue, 05 Mar 2019 23:18:40 +0100
User-agent: Evolution 3.30.5-1

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





reply via email to

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