Why can a Python script file not be named abc.py?

Viewed 514

One day when messing with Python in PyCharm, I encountered a quite silly problem. Namely, when I try to run a simple script in a file named abc.py, I receive an error. I tried to run the same file directly from the terminal and it looks fine.

abc.py

print("Hello world")

Output:

/Users/.../venv/bin/python /Users/.../abc.py
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/io.py", line 52, in <module>
  File "/Users/.../abc.py", line 1, in <module>
RuntimeError: lost sys.stdout

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Just out of curiosity, what is the matter here?

EDIT: Why does it happen only when running from PyCharm, and not when from the terminal?

2 Answers

You get an error because python is confused.

You see, there is a built in module in python, that is also called abc(short for 'Abstract Base Classes')!

I suggest you name your file something else, or the other crazy way,

delete the module (just kidding, don't do that!).

Related