[Python-ideas] Object grabbing

Bruce Leban bruce at leban.us
Mon May 2 10:35:38 EDT 2016


Using a single letter (or short) variable name works well most of the time
but has one problem: the variable can leak. It's easy to forget to write
the del statement. Imagine a block statement that had the effect of
deleting any variables initialized in the block. That is (using the with
keyword in this example but there are other choices):

    x = foo()
    with:
        y = x + 1
        x = y + 2

is equivalent to:

    x = foo()
    y = x + 1
    x = y + 2
    del y

or after optimization:

    x = (foo() + 1) + 2

[Obviously more useful with real code but this is sufficiently
illustrative. Also I imagine someone might say it's just foo() + 3 but I
don't know the type of foo().]

--- Bruce


-- 
--- Bruce
Check out my puzzle book and get it free here:
http://J.mp/ingToConclusionsFree (available on iOS)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160502/7942a0e0/attachment.html>


More information about the Python-ideas mailing list