Visit Official Exploding Ads Website

Saturday, October 10, 2015

dalke comments on "Blip: A bytecode compiler for Python 3"

By dalke

Here’s an example of why mborch’s statement is true:


 class A:
def __init__(self, value=0):
self.b = value
def __str__(self):
if self.b == 0:
global a
a = A(1)
elif self.b == 1:
import __builtin__, __main__
__builtin__.a = 2
del __main__.a
return str(self.b)
a = A()

def foo():
print a
print a
print a

foo()


This generates:


 1
2
3

but it’s a different ‘a’ in all three cases; the last isn’t even from the module’s namespace.


link


Read more here: ij9u



dalke comments on "Blip: A bytecode compiler for Python 3"

No comments:

Post a Comment