How to avoid "f.close" (no parens) bug?

Dave Kuhlman dkuhlman at rexx.com
Wed Feb 11 20:24:05 CET 2004


Batista, Facundo wrote:

[snip]
> 
> But, what's the point to have a...
> 
> t.spanish_inquisition
> 
> ...alone?

Here is an example:

    def test():
        myobject = MyClass()
        clean = myobject.my_really_long_method_name
        clean(a)
        clean(b)
        clean(c)
        clean(d)
        o
        o
        o

Basically, this is a poor-person's "with" statement, as in Pascal.
We've had people ask for that before. It can be used to save
typing, but also could make future changes easier.

Another example:

    def test(meth):
        o
        o
        o
        meth(a)
        o
        o
        o

    myobject = MyClass()
    test(myobject.some_method)
    test(myobject.some_other_method)

In this example, we've used a method as a parameter.

Dave

-- 
http://www.rexx.com/~dkuhlman
dkuhlman at rexx.com



More information about the Python-list mailing list