Terry J. Reedy <tjre...@udel.edu> added the comment:

What I missed before is that duplicating the effect of the first two 
interactive entries (no exception) requires escaping the backslash so that the 
source argument for the explicit compile does not have a null. 

compile("'\\0'", '', 'exec')
<code object <module> at 0x00000214431CAA20, file "", line 1>
compile("#\\0", '', 'exec')
<code object <module> at 0x00000214431CAC30, file "", line 1>

So I did not actually see an exception to the rule.
---

*On Win 10*, I experimented with a version of Armin and Irit's example, without 
and with b'...' and 'wb'.

s = '#\x00\na\nb\n' 
print(len(s))  # 7
with open("f:/Python/a/nulltest.py", 'w') as f:
  f.write(s)
import nulltest

When I ran a local repository build of 3.9, 3.10, or 3.11 with
  f:\dev\3x>python f:/Python/a/nulltest.py
I got Irit's strange NameError instead of the proper ValueError.

When I ran with installed 3.9 or 3.10 with
  py -3.10 -m a.nulltest
I got the null-byte ValueError.

When I ran from IDLE's editor running on either installed or repository python, 
the import gave the null-byte ValueError.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue20115>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to