Re: overriding methods - two questions

2007-11-16 Thread George Sakkis
On Nov 16, 5:03 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote: > >> Question 1: > > >> Given that the user of the API can choose to override foo() or not, how > >> can I control the signature that they use? > > > W

Re: implement random selection in Python

2007-11-16 Thread duncan smith
Bruza wrote: > On Nov 16, 4:47 pm, Bruza <[EMAIL PROTECTED]> wrote: >> On Nov 16, 6:58 am, duncan smith <[EMAIL PROTECTED]> >> wrote: >> >> >> >>> Bruza wrote: I need to implement a "random selection" algorithm which takes a list of [(obj, prob),...] as input. Each of the (obj, prob) repr

Re: implement random selection in Python

2007-11-16 Thread Steven D'Aprano
On Fri, 16 Nov 2007 16:47:16 -0800, Bruza wrote: > I think I need to explain on the probability part: the "prob" is a > relative likelihood that the object will be included in the output list. > So, in my example input of > > items = [('Mary',30), ('John', 10), ('Tom', 45), ('Jane', 15)] > > S

Re: implement random selection in Python

2007-11-16 Thread Jordan
How about this variation on your intial attempt? # Untested! def randomPick(n, items): def pickOne(): index = random.randint(0, 99) currentP = 0 for (obj, p) in items: currentP += p if currentP > index: return obj selection = set() while len(selection) < n:

Re: Interfaces.

2007-11-16 Thread Benjamin
On Nov 15, 7:55 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > Does anyone know what the state of progress with interfaces for python > (last I can see ishttp://www.python.org/dev/peps/pep-0245/) > > I would argue that interfaces/(similar feature) are necessary in any > modern languag

Re: overriding methods - two questions

2007-11-16 Thread Donn Ingle
>> While technically possible (using inspect.getargspec), trying to make >> your code idiot-proof is a lost fight and a pure waste of time. > Worse: it's actually counter-productive! > The whole idea of being able to subclass a class means that the user > should be able to override foo() *includi

Re: Global variables within classes.

2007-11-16 Thread Donn Ingle
Very interesting reply. I must ask a few questions, interleaved: > If you mean that all instances of Class Canvas and Thing will share > the *same* Stack, I think we can do it kind of like this: What's the difference between "same Stack" and "same instance of Stack"? I thought I knew what an insta

Re: overriding methods - two questions

2007-11-16 Thread Donn Ingle
> I am curious as to why you want to go through such contortions.  What > do you gain. for obj in list: if obj has a foo() method: a = something b = figureitout ( ) object.foo ( a, b ) I am accepting objects of any class on a stack. Depending on their nature I want to call certain methods

Re: Interfaces.

2007-11-16 Thread Chris M
On Nov 16, 12:26 am, James Stroud <[EMAIL PROTECTED]> wrote: > Chris M wrote: > > On Nov 15, 8:55 pm, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > >> Hi, > > >> Does anyone know what the state of progress with interfaces for python > >> (last I can see ishttp://www.python.org/dev/peps/pep-0

OT: good code snippet manager

2007-11-16 Thread Wensui Liu
Might anyone recommend a good code snippet manager to me? Thank you so much! -- === WenSui Liu (http://spaces.msn.com/statcompute/blog) === -- http://mail.python.org/mailman/listinfo/python-list

Re: Interfaces.

2007-11-16 Thread George Sakkis
On Nov 15, 8:55 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Does anyone know what the state of progress with interfaces for python > (last I can see ishttp://www.python.org/dev/peps/pep-0245/) No progress AFAIK for Python 2.x but Abstract Base Classes (ABCs) are pretty close to interface

Re: What is python?????

2007-11-16 Thread Hendrik van Rooyen
: "Thorsten Kampe" wrote: > * Cope (Fri, 16 Nov 2007 06:09:31 -0800 (PST)) > > please tell me what is python.This group is so crowded. > > A Python is dangerous snake[1]. This group here mainly consists of > misguided snake worshippers. You'd better run before they come to your > place... >

newbie Q: sequence membership

2007-11-16 Thread saccade
>>> a, b = [], [] >>> a.append(b) >>> b.append(a) >>> b in a True >>> a in a Traceback (most recent call last): File "", line 1, in RuntimeError: maximum recursion depth exceeded in cmp >>> >>> a is a[0] False >>> a == a[0] Traceback (most recent call last): File "", line 1, in RuntimeError:

Re: Resolving declaring class of a method at runtime

2007-11-16 Thread Janne Härkönen
On Nov 16, 2007 10:51 PM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Fri, 16 Nov 2007 19:02:25 +0200, Janne Härkönen > wrote: > > >> X is an "old style" class. Most people probably shouldn't use old style > >> classes, for various reasons. To use new style classes, you inherit > >> from object

Re: What is python?????

2007-11-16 Thread [EMAIL PROTECTED]
On Nov 16, 3:10�pm, Alan <[EMAIL PROTECTED]> wrote: > On Nov 16, 8:29 pm, [EMAIL PROTECTED] wrote: > > > I still don't get it and I've been haunting this group for months... > > > Mike > > Go on then �... > > What ? > > The punchline, do the punchline Punchline? I don't think there's a punchline s

Re: Interfaces.

2007-11-16 Thread Steven D'Aprano
On Fri, 16 Nov 2007 21:13:17 -0800, Chris M wrote: >> > Status:Rejected >> >> Thank you for pointing out the obvious. But *truly* helpful would be >> insight into "While at some point I expect that Python will have >> interfaces." Look for that sentence under the "rejected" part. >> >> James >

Re: What is python?????

2007-11-16 Thread Hendrik van Rooyen
(Mike) wrote: > On Nov 16, 1:16 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > On Nov 16, 8:14 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote: > > > > > * Cope (Fri, 16 Nov 2007 06:09:31 -0800 (PST)) > > > > > > please tell me what is python.This group is so crowded. > > > > > A Python is da

<    1   2