$ echo "Your code is bad and you should feel bad" > "<stdin>"
$ python
Python 3.6.0 (default, Dec 28 2016, 19:53:26)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 + '2'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Your code is bad and you should feel bad
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Почему Python путает строку "<stdin>"
с файлом, соответствующим этому имени файла? Я не хотел, чтобы Python пытался просто читать любые файлы с моего диска, если он столкнулся с необработанным исключением.
Вы также можете получить его с именем "<string>"
filename:
$ echo "pining for the fjords" > "<string>"
$ python -c 'wat'
Traceback (most recent call last):
File "<string>", line 1, in <module>
pining for the fjords
NameError: name 'wat' is not defined
Есть ли способ предотвратить это поведение или он жестко закодирован в REPL?