Accessing a method from within its own code

Paddy O'Loughlin patrick.oloughlin at gmail.com
Mon Nov 2 10:59:02 EST 2009


>
> I suspect that the "inspection" module has your answer, but that it'll be
> bulkier, and much slower than just doing what you're doing already.
>
Hmm.
Yeah, it does appear to be bulky. I don't think it's really any more use
than what I'm doing already.


Why not use the default arguments gimmick?  Since this cached item is to
> have a module lifetime, it'd be desirable to create it when the method is
> being defined, which is exactly what default arguments do.
>

I've a few different ways of emulating static function variables from C/Java
and the function/method attribute one is easily the one that appeals most to
my sensibilities.
I find the default arguments gimmick to be a gimmick. It's co-opting a piece
of functionality for something it doesn't seem like it was originally
intended for and as a consequence is less readable (to my eyes).
The only problem with the function/method way is that it gets rather verbose
when you are dealing with a user-defined method and have to give the class
name and method name and it's also a bit of a pain for moving code around
when refactoring.

You ever wish there was more to python scoping than just locals(), globals()
and __builtins__? Like a method's class's scope too?
That's where I am at with this.


-- 
"Ray, when someone asks you if you're a god, you say YES!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091102/5fdd085c/attachment-0001.html>


More information about the Python-list mailing list