[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#39070: python interpreter within Emacs fails on simple test (syntax
From: |
Federico Tedin |
Subject: |
bug#39070: python interpreter within Emacs fails on simple test (syntax error) |
Date: |
Tue, 04 Feb 2020 01:03:49 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
> 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#39070: python interpreter within Emacs fails on simple test (syntax error),
Federico Tedin <=