On 10/16/2017 11:21 AM, bartc wrote: > del x effectively removes it from the namespace so trying to use it on > line 4 generates the same 'undefined' error. > > However, the byte-code still needs to be aware of x: at the time when > line 1 is executed, the byte-code for line 3 already exists and it will > need to contain a reference to x.
I'm not sure why you'd think this, as we all know that code referring to a name involves a dictionary lookup at runtime. So the byte code for line does exist before x is defined, but it does not contain a "reference" to x in the manner you are thinking. Instead, all line three knows is that it must lookup the key "x" (as in string) in the dictionary of local or global objects. If it exists, great, if not, an exception is thrown. So no, there is no reference to x in the byte code before x is assigned. -- https://mail.python.org/mailman/listinfo/python-list