From: Federico Tedin <federicotedin@gmail.com>
To: "Pierre ALBARÈDE" <pa.com@free.fr>
Cc: 39070@debbugs.gnu.org
Subject: bug#39070: python interpreter within Emacs fails on simple test (syntax error)
Date: Tue, 04 Feb 2020 01:03:49 +0100 [thread overview]
Message-ID: <87blqfuska.fsf@gmail.com> (raw)
In-Reply-To: <f16b01bf-2138-17e5-b820-f627f145a542@free.fr> ("Pierre \=\?utf-8\?Q\?ALBAR\=C3\=88DE\=22's\?\= message of "Fri, 10 Jan 2020 11:29:58 +0000")
> Replacing 'if __name__ == "__main__":' by 'if True:', there is no more error.
>
> Replacing "__main__" by "__main_", there is no more error.
>
> Same with Python 3.7.6.
>
> 'print("main") if __name__ == '__main__' else print("not main")' works.
>
> Best regards.
Hello Pierre,
This behavior is due to `python-shell-send-buffer's SEND-MAIN
argument:
"When optional argument SEND-MAIN is non-nil, allow execution of
code inside blocks delimited by "if __name__== '__main__'" "
So when this argument is nil (the default), the whole block under "if
__name__== '__main__'" " will be removed (along the line containing the
"if" itself).
Your example breaks because you added an "else:" to your "if", so when
Emacs removes that part, a syntax error is raised.
Try the following test file:
print("1")
if __name__ == "__main__":
print("2")
print("3")
Using C-c C-c on it should yield "1 3", but using C-u C-c C-c
(i.e. SEND-MAIN set to t) should yield "1 2 3".
Hope that helps.
- Fede
next prev parent reply other threads:[~2020-02-04 0:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-10 11:29 bug#39070: python interpreter within Emacs fails on simple test (syntax error) Pierre ALBARÈDE
2020-02-04 0:03 ` Federico Tedin [this message]
2021-01-30 6:53 ` Lars Ingebrigtsen
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87blqfuska.fsf@gmail.com \
--to=federicotedin@gmail.com \
--cc=39070@debbugs.gnu.org \
--cc=pa.com@free.fr \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.