emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Philip Blagoveschensky <philip@crabman.me>
To: ian martins <ianxm@jhu.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: Bug: org-babel python with :results value sends function definition with a statement after a for loop to the shell incorrectly [9.3.6 (9.3.6-elpa @ /home/username/.emacs.d/elpa/org-9.3.6/)]
Date: Mon, 6 Jul 2020 22:18:31 +0300	[thread overview]
Message-ID: <5c1caa08-6c08-ebb9-ee81-76143c3a60b2@crabman.me> (raw)
In-Reply-To: <CAC=rjb7mx_XU5twYXfPAX0xEuH4AjpGehSKqqcGB3haDamkz7Q@mail.gmail.com>

Hi Ian,

 >Do you have the same issue if you aren't using a session?

If I run the following code block (this time I am using python 3, so 
there are parens in the print line)

#+begin_src python
def foobar():
     for i in range(5):
         pass
     print("hello world")
     return 3

return foobar()
#+end_src

I get

#+RESULTS:
: 3

so I know it worked fine.

But if I add session like this:

#+begin_src python :session bug_report
def foobar():
     for i in range(5):
         pass
     print("hello world")
     return 3

return foobar()
#+end_src

then in *bug_report* I get

 >>> def foobar():
...     for i in range(5):
...         pass
...
 >>>     print("hello world")
   File "<stdin>", line 1
     print("hello world")
     ^
IndentationError: unexpected indent
     return 3
 >>>
   File "<stdin>", line 1
     return 3
     ^
IndentationError: unexpected indent
 >>> return foobar()
 >>>
   File "<stdin>", line 1
SyntaxError: 'return' outside function
 >>> open('/tmp/babel-D0mRnD/python-CJ6UtT', 'w').write(str(_))
 >>>
20
 >>>
 >>> 'org_babel_python_eoe'
 >>> 'org_babel_python_eoe'
 >>>

 >Are you using tabs or spaces?

I used spaces. 4 spaces per indentation level, to be exact.

Also, FYI, as it might be relevant information, the shell buffer 
contents I posted above happen if the session has been created 
previously. If, instead, this is the first time I run some code in this 
session, then I also get another error - NameError (see below). Below 
you can see the contents of *bug_report* buffer if I run this code cell 
in a not-yet-existing session.

def foobar():
Python 3.8.2 | packaged by conda-forge | (default, Mar  5 2020, 17:11:00)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> ...     for i in range(5):
...         pass
...
 >>>     print("hello world")
   File "<stdin>", line 1
     print("hello world")
     ^
IndentationError: unexpected indent    return 3

 >>>
   File "<stdin>", line 1
     return 3
     ^
IndentationError: unexpected indent
 >>> return foobar()
 >>>
   File "<stdin>", line 1
SyntaxError: 'return' outside function
 >>> open('/tmp/babel-D0mRnD/python-MsDjEk', 'w').write(str(_))
 >>>
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
 >>>
 >>> 'org_babel_python_eoe'
 >>> 'org_babel_python_eoe'
 >>>

If you have a suggestion on how to debug this, feel free to tell.


  reply	other threads:[~2020-07-06 19:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30 11:09 Bug: org-babel python with :results value sends function definition with a statement after a for loop to the shell incorrectly [9.3.6 (9.3.6-elpa @ /home/username/.emacs.d/elpa/org-9.3.6/)] Philip Blagoveschensky
2020-07-06 12:57 ` ian martins
2020-07-06 19:18   ` Philip Blagoveschensky [this message]
2020-07-07 11:31     ` ian martins
2020-07-19 15:33       ` Jack Kamm
2020-10-10 23:57         ` Jack Kamm
  -- strict thread matches above, loose matches on Subject: below --
2020-07-01 16:55 Philip Blagoveschensky
2020-07-01 18:48 ` Andreas Röhler
2020-07-01 19:05 ` ian martins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5c1caa08-6c08-ebb9-ee81-76143c3a60b2@crabman.me \
    --to=philip@crabman.me \
    --cc=emacs-orgmode@gnu.org \
    --cc=ianxm@jhu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).