This small program runs well in Terminal :
mac2011% cat bug.py
print(__name__ == "__main__")
#if True:
if __name__ == "__main__":
print("main")
else:
print("not main")
mac2011% python bug.py
True
main
mac2011% python --version
Python 3.6.9 :: Anaconda, Inc.
In Emacs:
mac2011% Emacs --version
GNU Emacs 26.3
mac2011% Emacs -q bug.py
the file opens in (Python ElDoc) mode.
Python menu
Start interpreter (C-c C-p)
Eval buffer (C-c C-c)
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python.el: native completion setup loaded
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/alba/Documents/projets/plot time series/bug.py", line 5
else:
^
SyntaxError: invalid syntax
>>>
Replacing if __name__ == "__main__":
by if True:
, there is no more error.
Replacing "__main__"
by "__main_"
, there is no error.
Can you reproduce the facts?
Do you have any explanation?
How to repair?
Same with Python 3.7.6.
My emacs comes from Emacs for Mac OS X.
Same with emacs 28.0.50 that I have just built.
print("main") if __name__ == '__main__' else print("not main")
print("main") if __name__ == "__main__" else print("not main")
does not work today withEmacs 27.1