Lee Harr wrote:
I have a class with certain methods from which I want to select
one at random, with weighting.
The way I have done it is this
import random
def weight(value):
def set_weight(method):
method.weight = value
return method
return set_weight
class A(o
Steven D'Aprano wrote:
I agree with you that the simple explicit approach is better.
Now, to answer the question the OP didn't ask:
> def choose_with_weighting(actions, weights=None):
> if weights is None:
> weights = [1]*len(actions) # equal weights
> # Taken virtually unchanged
On Sep 17, 5:56 pm, Lee Harr <[EMAIL PROTECTED]> wrote:
> I have a class with certain methods from which I want to select
> one at random, with weighting.
>
> The way I have done it is this
>
> import random
>
> def weight(value):
> def set_weight(method):
> method.weight = value
On Thu, 18 Sep 2008 02:26:29 +0430, Lee Harr wrote:
> I have a class with certain methods from which I want to select one at
> random, with weighting.
>
> The way I have done it is this
[snip]
You are coupling the weights, the actions, and the object which chooses
an action all in the on
On Sep 17, 6:09 pm, "Aaron \"Castironpi\" Brady"
<[EMAIL PROTECTED]> wrote:
> On Sep 17, 4:56 pm, Lee Harr <[EMAIL PROTECTED]> wrote:
>
>
>
> > I have a class with certain methods from which I want to select
> > one at random, with weighting.
(snip)
>
> > The problem I have now is that if I subclas
On Sep 17, 4:56 pm, Lee Harr <[EMAIL PROTECTED]> wrote:
> I have a class with certain methods from which I want to select
> one at random, with weighting.
>
> The way I have done it is this
>
> import random
>
> def weight(value):
> def set_weight(method):
> method.weight = value
>
I have a class with certain methods from which I want to select
one at random, with weighting.
The way I have done it is this
import random
def weight(value):
def set_weight(method):
method.weight = value
return method
return set_weight
class A(object):
def a