From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id uEUgACh5A18+EgAA0tVLHw (envelope-from ) for ; Mon, 06 Jul 2020 19:19:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id +DGUNyd5A1/XDQAAB5/wlQ (envelope-from ) for ; Mon, 06 Jul 2020 19:19:03 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0D8A29408E8 for ; Mon, 6 Jul 2020 19:19:02 +0000 (UTC) Received: from localhost ([::1]:56542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsWdp-0002BE-HK for larch@yhetil.org; Mon, 06 Jul 2020 15:19:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsWdV-0002B6-00 for emacs-orgmode@gnu.org; Mon, 06 Jul 2020 15:18:41 -0400 Received: from forward106j.mail.yandex.net ([5.45.198.249]:60776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsWdS-0004lc-Qq for emacs-orgmode@gnu.org; Mon, 06 Jul 2020 15:18:40 -0400 Received: from mxback4o.mail.yandex.net (mxback4o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1e]) by forward106j.mail.yandex.net (Yandex) with ESMTP id 594D411A09DF; Mon, 6 Jul 2020 22:18:33 +0300 (MSK) Received: from sas2-ee0cb368bd51.qloud-c.yandex.net (sas2-ee0cb368bd51.qloud-c.yandex.net [2a02:6b8:c08:b7a3:0:640:ee0c:b368]) by mxback4o.mail.yandex.net (mxback/Yandex) with ESMTP id zHUker54ku-IXSqSqwC; Mon, 06 Jul 2020 22:18:33 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crabman.me; s=mail; t=1594063113; bh=7EfLRL1f9l5lhoN+Q2O9QlFpro2JzIcZ72j3JifmCeA=; h=In-Reply-To:From:To:Subject:Cc:Date:References:Message-ID; b=oXUWwGdSe70qb/exE22RABtcIbm4S3j09s6knlQ+JL/rzDTiU65pjnRYajfh9xdGp zTs9s+Y1GJIkjVs2G+FBz3yQ7QCUirEAD14w9N/fTqRh3cP1zVMl/E9V135ZQ2Dsxz wxtgtXKdHmeLneIbcWx7QmofgSzv1+a15pEW8i1M= Received: by sas2-ee0cb368bd51.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id onaaPGbhfD-IWli9HPZ; Mon, 06 Jul 2020 22:18:32 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) 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/)] To: ian martins References: From: Philip Blagoveschensky Message-ID: <5c1caa08-6c08-ebb9-ee81-76143c3a60b2@crabman.me> Date: Mon, 6 Jul 2020 22:18:31 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: none client-ip=5.45.198.249; envelope-from=philip@crabman.me; helo=forward106j.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/06 15:18:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=crabman.me header.s=mail header.b=oXUWwGdS; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.21 X-TUID: rb/D+XNf0qIX 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 "", line 1 print("hello world") ^ IndentationError: unexpected indent return 3 >>> File "", line 1 return 3 ^ IndentationError: unexpected indent >>> return foobar() >>> File "", 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 "", line 1 print("hello world") ^ IndentationError: unexpected indent return 3 >>> File "", line 1 return 3 ^ IndentationError: unexpected indent >>> return foobar() >>> File "", line 1 SyntaxError: 'return' outside function >>> open('/tmp/babel-D0mRnD/python-MsDjEk', 'w').write(str(_)) >>> Traceback (most recent call last): File "", line 1, in 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.