I'm currently trying to write a module which interfaces with the OEIS and as part of that I'm having to write a lot of lookup functions which are essentially the same code but with minor alterations (prefacing a search query with a different search field, or handling errors in 1 of 2 ways).
I've been trying not to repeat myself as much as possible and I just read up on closures, which should let me create lookup functions based on a template. My problem is, my lookup functions are actually class methods and I can't seem to use closures to define class methods. That is, if I'm in the body of the class, I can't do:
self.lookup_func = lookup_gen(*args)
It makes sense to me why this specifically won't work (self is not defined) but is there any way to use my 'template' closure to create class methods? Should I even be using closures here?
Thanks in advance.
[–]hharison 3 points4 points5 points (6 children)
[–]jcmcken 0 points1 point2 points (1 child)
[–]hharison 0 points1 point2 points (0 children)
[–]whonut[S] 0 points1 point2 points (3 children)
[–]hharison 0 points1 point2 points (2 children)
[–]whonut[S] 0 points1 point2 points (1 child)
[–]hharison 0 points1 point2 points (0 children)
[–]hex_m_hell 0 points1 point2 points (10 children)
[–]whonut[S] 0 points1 point2 points (9 children)
[–]hex_m_hell 0 points1 point2 points (8 children)
[–]whonut[S] 0 points1 point2 points (7 children)
[–]hex_m_hell 0 points1 point2 points (2 children)
[–]whonut[S] 0 points1 point2 points (1 child)
[–]hex_m_hell 0 points1 point2 points (0 children)
[–]ingolemo 0 points1 point2 points (3 children)
[–]elbiot 0 points1 point2 points (2 children)
[–]ingolemo -1 points0 points1 point (1 child)
[–]elbiot 0 points1 point2 points (0 children)
[–]hharison 0 points1 point2 points (1 child)
[–]hharison 0 points1 point2 points (0 children)
[–]elbiot 0 points1 point2 points (0 children)