Guido van Rossum said: [Christos] >> A minor correction: the Voodoo approach handles fine method calls by >> defining a __call__ method in the Voodoo class; [...] >> >> lambda x: x.startswith("text") >> This works fine as: >> Voodoo().startswith("text") > >Hm. But the whole point of Voodoo is that the resulting object has a >__call__ method that evaluates the expression for a given argument. >How do you do that? (I suppose you can do it if you don't do >chaining, but I like the chaining.) (replying to Phillip Eby too) Yes, you are correct (I was thinking in terms of my All and Any classes, which don't need to be used as callables). There is a solution involving a Voodoo and an (unexported) VoodooAttribute class which *can* solve this (Voodoo.__getattr__ returns an instance of VoodooAttribute (subclass of Voodoo overloading __call__), whose .__call__ method returns an instance of Voodoo), *but* then you can't use: Voodoo().startswith # this is a VoodooAttribute instance as an argument to groupby, unless you use: Voodoo(Voodoo().startswith) # this is a Voodoo instance I can't think at the moment a case in the groupby context where the latter would be needed (a VoodooAttribute behaves the same for attributes that are not methods), but I'm sure many others will, and even if they don't, it sure smells 'breakage'. Unless the Voodoo class does what it does best (and I'll rename it to Argument for clarity below), and an instance of it is the only argument to the *explicit* initialisation of the FuncMaker class (the final Voodoo :): lambda x: x.startswith("text") equals FuncMaker(Argument().startswith("text")) Too unpythonic perhaps? PS attrgetter and itemgetter sound fine btw, I'm just trying to help this brainstorming for more general solutions --if any. -- TZOTZIOY, I speak England very best, Ils sont fous ces Redmontains! --Harddix
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