Re: 79 chars or more?

2010-08-19 Thread Roald de Vries
Dear Jean-Michel, On Aug 18, 2010, at 10:57 AM, Jean-Michel Pichavant wrote: At least, if you still want to stick with 79 chars, do something like text = find(response, 'MPNExpirationDate', ).text self.expiration_date = translate_date(text,'%Y-%m-%d', '%m%d%Y') I don't necessarily like this

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-16 Thread Roald de Vries
On Aug 15, 2010, at 11:51 PM, Ian Kelly wrote: On Sun, Aug 15, 2010 at 4:36 PM, Baba raoul...@gmail.com wrote: Hi Mel, indeed i thought of generalising the theorem as follows: If it is possible to buy n, n+1,…, n+(x-1) sets of McNuggets, for some x, then it is possible to buy any number of

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-16 Thread Roald de Vries
On Aug 16, 2010, at 5:04 PM, Ian Kelly wrote: On Mon, Aug 16, 2010 at 4:23 AM, Roald de Vries downa...@gmail.com wrote: I suspect that there exists a largest unpurchasable quantity iff at least two of the pack quantities are relatively prime, but I have made no attempt to prove

Re: Python why questions

2010-08-15 Thread Roald de Vries
On Aug 15, 2010, at 1:00 PM, Lawrence D'Oliveiro wrote: It would be if pointers and arrays were the same thing in C. Only they’re not, quite. Which somewhat defeats the point of trying to make them look the same, don’t you think? How are they not the same? The code snippet (in C/C++)

Re: Python why questions

2010-08-15 Thread Roald de Vries
On Aug 7, 2010, at 9:14 PM, John Nagle wrote: FORTRAN, MATLAB, and Octave all use 1-based subscripts. The languages which have real multidimensional arrays, rather than arrays of arrays, tend to use 1-based subscripts. That reflects standard practice in mathematics. True, but that

Re: Python why questions

2010-08-15 Thread Roald de Vries
On Aug 15, 2010, at 2:16 PM, geremy condra wrote: On Sun, Aug 15, 2010 at 4:55 AM, Roald de Vries downa...@gmail.com wrote: On Aug 15, 2010, at 1:00 PM, Lawrence D'Oliveiro wrote: It would be if pointers and arrays were the same thing in C. Only they’re not, quite. Which somewhat defeats

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-13 Thread Roald de Vries
On Aug 12, 2010, at 10:51 PM, John Posner wrote: On 8/12/2010 9:22 AM, Dave Angel wrote: Now you have to find the largest number below 120, which you can easily do with brute force tgt = 120 # thanks, Dave Angel Anytime, but I'm not Dave Angel. My previous algorithm was more efficient,

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-13 Thread Roald de Vries
On Aug 13, 2010, at 12:25 PM, Roald de Vries wrote: My previous algorithm was more efficient, but for those who like one- liners: [x for x in range(120) if any(20*a+9*b+6*c == x for a in range(x/20) for b in range(x/9) for c in range(x/6))][-1] OK, I did some real testing now, and there's

Re: python ide for ubuntu

2010-08-12 Thread Roald de Vries
Hi Bhanu, On Aug 12, 2010, at 4:15 AM, Bhanu Kumar wrote: Hi All, Is there any good free python IDE available in Ubuntu? See a similar discussion at django-users mailing list: http://groups.google.com/group/django-users/browse_thread/thread/562189578285211 Cheers, Roald --

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread Roald de Vries
On Aug 12, 2010, at 11:33 AM, Paul Rubin wrote: Baba raoul...@gmail.com writes: exercise: given that packs of McNuggets can only be bought in 6, 9 or 20 packs, write an exhaustive search to find the largest number of McNuggets that cannot be bought in exact quantity. Is that a homework

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread Roald de Vries
On Aug 12, 2010, at 9:02 PM, Peter Otten wrote: Baba wrote: Thank You for helping me out. Indeed i am not looking for the code but rather for hints that direct my reasoning as well as hints as to how to write basic programs like this. You have broken down the approach into 2 parts. I

Re: Class initialization

2010-08-08 Thread Roald de Vries
On Aug 8, 2010, at 3:32 PM, Costin Gament wrote: Hi there. I'm kind of a beginner with Python (and programming in general). My problem is with initializing a class. Let's say I've defined it like this: class foo: a = 0 b = 0 and later I'm trying to initialize two different classes like

Re: Class initialization

2010-08-08 Thread Roald de Vries
the 'a' variable in c2 it has the same value as the 'a' variable in c1. Am I missing something? I can't reproduce this. Which version are you using? On Sun, Aug 8, 2010 at 4:59 PM, Roald de Vries downa...@gmail.com wrote: Your problem probably is that a and b are class variables; And class

Re: Python why questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 5:46 AM, Vito 'ZeD' De Tullio wrote: Default User wrote: From the emperor's new clothes department: 1) Why do Python lists start with element [0], instead of element [1]? Common sense would seem to suggest that lists should start with [1].

Re: Python why questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 2:54 PM, D'Arcy J.M. Cain wrote: On Sat, 07 Aug 2010 13:48:32 +0200 News123 news1...@free.fr wrote: It makes sense in assembly language and even in many byte code languages. It makes sense if you look at the internal representation of unsigned numbers (which might become an

iterators and continuing after a StopIteration

2010-08-07 Thread Roald de Vries
Hi all, I have a list that I'm iterating over, and during the iteration items are appended. Moreover, it is iterated over in two nested loops. If the inner loop comes to the end, I want the outer loop to append an item. Is there a way to do this? Because once an iterator has raised a

Re: Python why questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 3:53 PM, D'Arcy J.M. Cain wrote: On Sat, 7 Aug 2010 15:37:23 +0200 Roald de Vries downa...@gmail.com wrote: Would said beginner also be surprised that a newborn baby is zero years old or would it be more natural to call them a one year old? Zero based counting is perfectly

Re: Python why questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 5:24 PM, Nobody wrote: On Sat, 07 Aug 2010 13:48:32 +0200, News123 wrote: Common sense is wrong. There are many compelling advantages to numbering from zero instead of one: http://lambda-the-ultimate.org/node/1950 It makes sense in assembly language and even in many

Re: easy question on parsing python: is not None

2010-08-06 Thread Roald de Vries
On Aug 6, 2010, at 9:25 AM, Bruno Desthuilliers wrote: Roald de Vries a écrit : 'not None' first casts None to a bool, and then applies 'not', so 'x is not None' means 'x is True'. Obviously plain wrong : Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help

[issue9533] metaclass can't derive from ABC

2010-08-06 Thread Roald de Vries
New submission from Roald de Vries pyt...@roalddevries.nl: Exception raised:: Traceback (most recent call last): File bug.py, line 5, in module class derived(type, Sized): File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/abc.py, line 85

abstract metaclass

2010-08-05 Thread Roald de Vries
Hi all, I'm trying to create a metaclass that keeps track of its objects, and implement this as a collections.MutableMapping. That is, something like this: class type2(type, MutableMapping): ... /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/abc.pyc in

Re: easy question on parsing python: is not None

2010-08-05 Thread Roald de Vries
On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: How does x is not None make any sense? not x is None does make sense. I can only surmise that in this context (preceding is) not is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(X, None) Beside not in

Re: easy question on parsing python: is not None

2010-08-05 Thread Roald de Vries
On Aug 5, 2010, at 6:11 PM, Chris Rebert wrote: On Thu, Aug 5, 2010 at 8:56 AM, Roald de Vries downa...@gmail.com wrote: On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: How does x is not None make any sense? not x is None does make sense. I can only surmise that in this context

Re: subclassing versus object redefinition

2010-08-03 Thread Roald de Vries
On Aug 3, 2010, at 2:46 PM, wheres pythonmonks wrote: Hi! I have a class (supposed to be an abstract base class): In python (as opposed to static languages like C++) I don't seed to subclass the base class, but instead I can simply override the behavior of stub methods and values. Is there a

Re: subclassing versus object redefinition

2010-08-03 Thread Roald de Vries
Hi W, On Aug 3, 2010, at 4:38 PM, wheres pythonmonks wrote: I think that the crux of the matter is in points #3, #4, and #5 that you raised: I think #2 is important too: a program is supposed to do what you expect, and I don't expect instantiation of an ABC. On #3: Not clear that all

Re: simple integer subclass

2010-08-03 Thread Roald de Vries
Hi Andreas, On Aug 3, 2010, at 1:52 AM, Andreas Pfrengle wrote: I'm trying to define a subclass of int called int1. An int1-object shall behave exactly like an int-object, with the only difference that the displayed value shall be value + 1 (it will be used to display array indices starting at

Re: floatref

2010-07-14 Thread Roald de Vries
On Jul 14, 2010, at 1:26 AM, Gary Herron wrote: On 07/13/2010 03:02 PM, Roald de Vries wrote: Hi Gary, On Jul 13, 2010, at 8:54 PM, Gary Herron wrote: On 07/13/2010 10:26 AM, Roald de Vries wrote: Hi all, I have two objects that should both be able to alter a shared float. So i need

Re: floatref

2010-07-14 Thread Roald de Vries
On Jul 14, 2010, at 3:53 AM, Steven D'Aprano wrote: On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: Hi all, I have two objects that should both be able to alter a shared float. So i need something like a mutable float object, or a float reference object. Does anybody know

Re: floatref

2010-07-14 Thread Roald de Vries
On Jul 14, 2010, at 3:53 AM, Steven D'Aprano wrote: On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: Hi all, I have two objects that should both be able to alter a shared float. So i need something like a mutable float object, or a float reference object. Does anybody know

floatref

2010-07-13 Thread Roald de Vries
Hi all, I have two objects that should both be able to alter a shared float. So i need something like a mutable float object, or a float reference object. Does anybody know if something like that exists? I know it's not hard to build, but I have a feeling that there should be a standard

Re: map is useless!

2010-06-06 Thread Roald de Vries
On Jun 6, 2010, at 5:16 PM, rantingrick wrote: Everyone knows i'm a Python fanboy so nobody can call me a troll for this... Python map is just completely useless. For one it so damn slow why even bother putting it in the language? And secondly, the total girl- man weakness of lambda renders it

Re: dictionary

2010-04-27 Thread Roald de Vries
On Apr 26, 2010, at 8:04 PM, gopi krishna wrote: When I give a dictionary with key and value in order how can get back iy in same order I use YAML a lot, which supports ordered dicts, and these are interpreted as lists of pairs by Python, so that might be a good choice. --

Interfaces

2010-04-05 Thread Roald de Vries
Dear all, PEP 245 and 246 about interfaces for python are both rejected for 'something much better' (GvR in 246's rejection notice). Does anybody know what this is? I am *very* curious! Kind regards, Roald -- http://mail.python.org/mailman/listinfo/python-list

Re: Renaming identifiers debugging

2010-02-26 Thread Roald de Vries
Hi Luca, On Feb 26, 2010, at 12:41 AM, Luca wrote: MRAB wrote: Perhaps you could use a different extension, eg .pyn, so existing .py files are handled as-is but .pyn files are read through a translator. This could be a good idea... especially since i could make my own extension since we

Re: When will Python go mainstream like Java?

2010-02-23 Thread Roald de Vries
On Feb 22, 2010, at 10:56 PM, AON LAZIO wrote: That will be superb I guess static typing will have to be added, so that tools like eclipse can inspect (and autocomplete) your programs [better]. -- http://mail.python.org/mailman/listinfo/python-list

Re: Constraints on __sub__, __eq__, etc.

2010-02-19 Thread Roald de Vries
On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov anfedo...@gmail.comwrote: It seems intuitive to me that the magic methods for overriding the +, -, , ==, , etc. operators should have no sideffects on their operands. Also, that == should be

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-19 Thread Roald de Vries
This pipeline idea has actually been implemented further, see http:// blog.onideas.ws/stream.py. from stream import map, filter, cut range(10) map(lambda x: [x**2, x**3]) filter(lambda t: t[0]! =25 and t[1]!=64) cut[1] list [0, 1, 8, 27, 216, 343, 512, 729] Wow, cool! Just to show that

Re: Your beloved python features

2010-02-05 Thread Roald de Vries
On Feb 5, 2010, at 12:03 AM, Julian wrote: Hello, I've asked this question at stackoverflow a few weeks ago, and to make it clear: this should NOT be a copy of the stackoverflow-thread hidden features of Python. I want to design a poster for an open source conference, the local usergroup will

Re: Symbols as parameters?

2010-01-29 Thread Roald de Vries
On Jan 29, 2010, at 2:30 AM, Steven D'Aprano wrote: On Thu, 28 Jan 2010 17:01:38 +0100, Roald de Vries wrote: Question out of general interest in the language: If I would want to generate such functions in a for-loop, what would I have to do? This doesn't work: class Move(object): def

Re: Symbols as parameters?

2010-01-28 Thread Roald de Vries
On Jan 22, 2010, at 11:56 AM, Roald de Vries wrote: Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g. def move (direction

Re: Python and Ruby

2010-01-27 Thread Roald de Vries
On Jan 27, 2010, at 2:01 PM, Jean Guillaume Pyraksos wrote: What are the arguments for choosing Python against Ruby for introductory programming ? Python has no provisions for tail recursion, Ruby is going to... So what ? Thanks, I think the main difference is in culture, especially for

enumerated while loop

2010-01-23 Thread Roald de Vries
Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function like 'naturals' already exists, or a similar construction for the same

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:50 PM, Grant Edwards wrote: On 2010-01-23, Roald de Vries r...@roalddevries.nl wrote: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:49 PM, Diez B. Roggisch wrote: Am 23.01.10 15:44, schrieb Roald de Vries: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:58 PM, Mark Dickinson wrote: On Jan 23, 2:44 pm, Roald de Vries r...@roalddevries.nl wrote: I assume a function like 'naturals' already exists, or a similar construction for the same purpose. But what is it called? itertools.count() On Jan 23, 2010, at 4:04 PM, Jan

Re: Symbols as parameters?

2010-01-22 Thread Roald de Vries
Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g. def move (direction): ... If direction can only be up, down, left or right, you can

Re: Symbols as parameters?

2010-01-22 Thread Roald de Vries
On Jan 22, 2010, at 1:06 PM, Martin Drautzburg wrote: On 22 Jan., 11:56, Roald de Vries r...@roalddevries.nl wrote: Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume

Re: detect interactivity

2009-12-30 Thread Roald de Vries
On Dec 30, 2009, at 4:10 AM, Steve Holden wrote: Roald de Vries wrote: On Dec 30, 2009, at 2:28 AM, Dave Angel wrote: Roald de Vries wrote: On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all

detect interactivity

2009-12-29 Thread Roald de Vries
Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions that are only useful in interactive mode. Kind regards, Roald -- http://mail.python.org/mailman/listinfo/python-list

Re: detect interactivity

2009-12-29 Thread Roald de Vries
On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions that are only useful

Re: detect interactivity

2009-12-29 Thread Roald de Vries
On Dec 30, 2009, at 1:52 AM, Steven D'Aprano wrote: On Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries wrote: Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions that are only useful in interactive mode. Ah

Re: detect interactivity

2009-12-29 Thread Roald de Vries
On Dec 30, 2009, at 2:28 AM, Dave Angel wrote: Roald de Vries wrote: On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all, Is it possible for a Python script to detect whether it is running