"Alex Martelli" <aleaxit at yahoo.com> writes: > <James_Althoff at i2.com> wrote in message > news:mailman.988052255.6016.python-list at python.org... > > Now suppose the call to collection.do(xxx) is in the middle of a > > very long class def. > > OK, let's suppose that. > > > Then I have to put the doThisAndDoThatToItem > > def before the class or after the class thereby separating the definition > > from its one and only use by possibly hundreds of lines of > > code. This is not nice for readability. Or I have to define > > doThisAndDoThatToItem > > as a method in my class which clutters my class with an unnecessary > > method. > > Ah, I see, you're in the one and only case in Python where you > can't just immediately def a function for your purpose, because > doing that would magically make it into a method -- smack in > the middle of a class body. Well, during the execution of the class statement the function is not yet a method: >>> class C: ... def f(self): ... print self ... print type(f) ... <type 'function'> and you can get rid of f with del afterwards: >>> class C: ... def f(self): ... print self ... f(1) ... del f ... 1 >>> Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://mapit.de/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4