RE: c[:]()



Hey Douglas,

Perhaps I was being too abstract? Here goes:

,-------------------------------
| def selector():
| ...
| return funcKey #get down get down
|
| def func():
| ...
| funcSwitch = {}
| funcSwitch[funcKey] = func
| ...
| funcSwitch[selector()]()


even more interesting is a

,----------------------------------------
| def judge(contestants):
| for contestant in contestants:
| ...
| if answersQuestionToSatisfaction:
| yield semiFinalist
|
| beauty[judge(beauty)]()

hmmmm, I suppost you could just call

judge(beauty)

and have the judge call the contestant personally.
But that may be *too* personal. Moreover, what about
the other judges? Wouldn't it be best to simply state:

beauty[judges[:](beauty)].thankyouForThisOpportunity()

This allows each judge to choose differently while all
the contestants behave consistently. It kind of like an
off the cuff decorator for generators, where

beauty[...].decoration()

Maybe there's a better way of doing this? I don't know.


def a(): return 'b'
def b(): print 'polly! wakey wakey'
c = {}
c['a'] = b
c[a()]() #works!


(typo correction for other easily-confused newbies like myself)

I think you mean
,----
| c['a']() #works!
`----


Oh no, I get it, you meant...
,----
| c['b'] = b
| c[a()]() #works!
`----

...or was it?:-
,----
| def a(): return 'a'
`----

--
Doug Woodrow

--
http://mail.python.org/mailman/listinfo/python-list


.



Relevant Pages

  • Re: Docorator Disected
    ... > def get_function(function): # Get func object off stack ... To understand decorator chains it is very helpfull to accept the ... def default: ... The function mul defines the inner functions default, ...
    (comp.lang.python)
  • Re: Name conflict in class hierarchy
    ... def func: ... print 'In B.func, calling A.f1' ... functionality, and I call the new function "func". ... you don't override existing methods in that class unintentionally. ...
    (comp.lang.python)
  • better scheduler with correct sleep times
    ... self.queue.put((fire_at, func, arg)) ... def runner: ... The scheduler goes to sleep for 10 seconds ...
    (comp.lang.python)
  • Re: Confessions of a Python fanboy
    ... Python functions and methods are first class objects. ... def factory_function: ... Python's model is consistent and simple: given a function "func", ...
    (comp.lang.python)
  • Re: optimization
    ... Neal> def something: ... Neal> It appears that if Func is called many times, ... If the inner function is constant and does not directly access outer function locals, and if every last tick of speed is a concern, then it can be move out and given a name like _outer_helper. ...
    (comp.lang.python)