Re: Optional parameter object re-used when instantiating multiple objects

2008-11-15 Thread Arnaud Delobelle
Rick Giuly <[EMAIL PROTECTED]> writes: > Hello All, Hello, > Why is python designed so that b and c (according to code below) > actually share the same list object? It seems more natural to me that > each object would be created with a new list object in the points > variable. > > class Blob: >

Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-15 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > I have yet to see any reasonable definition of a Python > value in the Python docs or elsewhere, despite the fact > that a value is one of the three defining characteristics > of an object, a central concept in Python. I don't remember how the expression 'object value'

Re: Comparing value in two dictionaries?

2008-11-15 Thread Arnaud Delobelle
Gilles Ganault <[EMAIL PROTECTED]> writes: > Hello > > I fill two dictionaries with the same number of keys, and then need to > compare the value for each key, eg. > > #Pour chaque APE, comparaison societe.ape.nombre et verif.ape.nombre > import apsw > > # > dic1={} > [...] > rows=list

Re: Regular expression and exception

2008-11-15 Thread Arnaud Delobelle
Mr.SpOOn <[EMAIL PROTECTED]> writes: > Hi, > I've never used exception before, but I think now it's time to start. > > I've seen that there is a list of the built-in exceptions in the > Python docs, but this explains the meaning of every exception. Does > exist an inverted list? I mean, how may I

Re: Comparing value in two dictionaries?

2008-11-15 Thread Arnaud Delobelle
Scott David Daniels <[EMAIL PROTECTED]> writes: > Arnaud Delobelle wrote: >> Gilles Ganault <[EMAIL PROTECTED]> writes: >> >>> Hello >>> >>> I fill two dictionaries with the same number of keys, and then need to >>> compare the value

Re: Generators and their next() and send() methods

2008-11-15 Thread Arnaud Delobelle
Thomas Mlynarczyk <[EMAIL PROTECTED]> writes: > Hello, > > I was playing around a bit with generators using next() and > send(). And I was wondering why an extra send() method was introduced > instead of simply allowing an argument for next(). > > Also, I find it a bit counter-intuitive that send(

Re: Comparing value in two dictionaries?

2008-11-15 Thread Arnaud Delobelle
Arnaud Delobelle <[EMAIL PROTECTED]> writes: > Or to obtain a dictionary of differences: > > dict((k, (v, dic2[v]) for k, v in dic1.iteritems() > if dic2[v] != v) ^ Should be k of c

Re: Optional parameter object re-used when instantiating multiple objects

2008-11-15 Thread Arnaud Delobelle
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Sat, 15 Nov 2008 01:40:04 -0800, Rick Giuly wrote: > >> Hello All, >> >> Why is python designed so that b and c (according to code below) >> actually share the same list object? It seems more natural to me that >> each object would be created with

Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-16 Thread Arnaud Delobelle
Derek Martin <[EMAIL PROTECTED]> writes: > On Thu, Nov 13, 2008 at 11:58:18AM -0800, [EMAIL PROTECTED] wrote: >> I have yet to see any reasonable definition of a Python value in the >> Python docs or elsewhere, despite the fact that a value is one of >> the three defining characteristics of an obj

Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-16 Thread Arnaud Delobelle
Derek Martin <[EMAIL PROTECTED]> writes: > I think he meant None... Or at least, I personally see a distinction > between zero and None (and so do the Python docs). Zero is a value, > whereas None is specifically intended to denote the lack of any value. None is an 'value' which is intended to

Re: Customizing sequence types

2008-11-16 Thread Arnaud Delobelle
Mr.SpOOn <[EMAIL PROTECTED]> writes: > Hi, > I'm trying to create a class which inherit a list to change some behavior. > This list should contain other instance objects and has to manage > these instances in a particular way. > > 1) I need to sort this elements in this list, but they must be sort

Re: Customizing sequence types

2008-11-17 Thread Arnaud Delobelle
Terry Reedy <[EMAIL PROTECTED]> writes: > Mr.SpOOn wrote: >> On Sun, Nov 16, 2008 at 7:15 PM, Arnaud Delobelle > >>> You should probably use the `bisect` module >>> (http://docs.python.org/library/bisect.html) for searching and >>> inserting into the l

Re: Python-URL! - weekly Python news and links (Nov 17)

2008-11-17 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > I guess this goes a long way to explaining why the Python docs > suck so badly in many areas. I like the python docs very much. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggestions for an education programming project

2008-11-17 Thread Arnaud Delobelle
Eric <[EMAIL PROTECTED]> writes: > Hi, > > I've been trying to get my son interested in learning some simple > programming for a while. While I understand that a structured tutorial > is best, I think if we can write something cool at least once, it will > encourage him to learn more. I know it's

Re: Multiple equates

2008-11-17 Thread Arnaud Delobelle
jzakiya <[EMAIL PROTECTED]> writes: > I looked online and in books, but couldn't find a definitive answer to > this. > > I have an array and set multiple elements to either True or False at > one time. > > Question: Which way is faster (or does it matter)? > > 1) > > array[x1]=array[x2]==

Re: Multiple equates

2008-11-17 Thread Arnaud Delobelle
Arnaud Delobelle <[EMAIL PROTECTED]> writes: > jzakiya <[EMAIL PROTECTED]> writes: > >> I looked online and in books, but couldn't find a definitive answer to >> this. >> >> I have an array and set multiple elements to either True or False at >&

Re: Avoiding local variable declarations?

2008-11-18 Thread Arnaud Delobelle
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: > On Tue, 18 Nov 2008 00:18:51 +, Steven D'Aprano wrote: > >> On Mon, 17 Nov 2008 12:32:35 +, Marc 'BlackJack' Rintsch wrote: >> >>> Not such illogical crap like >>> ``a = a + 1`` which must be obviously false unless 1 is defined as the

Re: sorting list of complex numbers

2008-11-18 Thread Arnaud Delobelle
Paul Rubin writes: > for fancier structures you'd need a full blown class implementation > with an init method. Either way you end up temporarily allocating a > lot of extra structures, but at least they're not all in memory > simultaneously like in the DSU pattern. Th

Re: Avoiding local variable declarations?

2008-11-19 Thread Arnaud Delobelle
greg <[EMAIL PROTECTED]> writes: > Arnaud Delobelle wrote: > >> Neutral element is correct. But maybe its use is limited to >> mathematicians in the english-speaking word. > > I've only ever seen "identity element" in English mathematics. >

Re: Designing superclasses so inherited methods return objects with same type as the instance.

2008-11-19 Thread Arnaud Delobelle
"Felix T." <[EMAIL PROTECTED]> writes: > I have a class called Interval(type.ObjectType) that is supposed to > mimic closed mathematical intervals. Right now, it has a lot of > methods like this: > > def __add__(self,other): > if type(other) in Numerical: > return Interval(

Re: Programming exercises/challenges

2008-11-19 Thread Arnaud Delobelle
Edwin <[EMAIL PROTECTED]> writes: [...] > a diary manager compatible with my Emacs diary file (sometimes I don't > want to open Emacs for a quick note) You mean that you sometimes don't have emacs open? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Module Structure/Import Design Problem

2008-11-19 Thread Arnaud Delobelle
Rafe <[EMAIL PROTECTED]> writes: > Hi, > > I am in a situation where I feel I am being forced to abandon a clean > module structure in favor of a large single module. If anyone can save > my sanity here I would be forever grateful. > > My problem is that classes in several modules share a common b

Re: How to get the class instance of a passed method ?

2008-11-20 Thread Arnaud Delobelle
Christian Heimes <[EMAIL PROTECTED]> writes: > Stef Mientki wrote: >> hello, >> >> if I pass a class method to a function, >> is it possible to determine the class instance in that function ? >> >> class test ( object ) : >> def My_Method ( self ) : >>return 22 >> >> def do_something ( param

Re: function parameter scope python 2.5.2

2008-11-20 Thread Arnaud Delobelle
J Kenneth King <[EMAIL PROTECTED]> writes: > I recently encountered some interesting behaviour that looks like a bug > to me, but I can't find the appropriate reference to any specifications > to clarify whether it is a bug. > > Here's the example code to demonstrate the issue: > > class SomeObjec

Re: Python 3 __cmp__ semantic change?

2008-11-21 Thread Arnaud Delobelle
Hyuga <[EMAIL PROTECTED]> writes: > On Nov 21, 4:09 am, Duncan Booth <[EMAIL PROTECTED]> wrote: >> Johannes Bauer <[EMAIL PROTECTED]> wrote: >> > Seems it was removed on purpose - I'm sure there was a good reason for >> > that, but may I ask why? Instead of the sleek __cmp__ function I had >> > ea

Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Arnaud Delobelle
Slaunger <[EMAIL PROTECTED]> writes: > I am a Python novice, and I have run into a problem in a project I am > working on, which boils down to identifying the patterns in a sequence > of integers, for example > > 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6 > 1 6 6 1 6 6 1

Re: can the sequence of entries in a dictionary be depended on?

2008-11-21 Thread Arnaud Delobelle
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > Priya wrote: > >> Hi, >> I'm writing a program where i iterate through the entries in a >> dictionary using a for loop. This for-loop is enclosed by another loop >> which traverses through a list and checks the relation between each >> entry in the

Re: __new__ woes with list

2008-11-21 Thread Arnaud Delobelle
macaronikazoo <[EMAIL PROTECTED]> writes: > i'm having a hell of a time getting this to work. basically I want to > be able to instantiate an object using either a list, or a string, but > the class inherits from list. > > if the class is instantiated with a string, then run a method over it > to

Re: __new__ woes with list

2008-11-21 Thread Arnaud Delobelle
macaronikazoo <[EMAIL PROTECTED]> writes: > ok thansk - i will search again. i did try searching but didn't find > anything relevant... Here's a link to the thread on google groups: http://groups.google.com/group/comp.lang.python/browse_thread/thread/7aff4eabc6182858 Unfortunately two threads

Re: how to dynamically instantiate an object inheriting from several classes?

2008-11-21 Thread Arnaud Delobelle
Joe Strout <[EMAIL PROTECTED]> writes: > I have a function that takes a reference to a class, and then > instantiates that class (and then does several other things with the > new instance). This is easy enough: > >item = cls(self, **itemArgs) > > where "cls" is the class reference, and itemA

Re: Programming exercises/challenges

2008-11-22 Thread Arnaud Delobelle
Edwin <[EMAIL PROTECTED]> writes: > I have to point out that I myself use Vim more than > Emacs. Not because I think it's better (I'm not a religious person) > but because it has better integration with my Mac... and actually, I > use them for different programming tasks. I'm only a very occasion

Re: Python 3 __cmp__ semantic change?

2008-11-22 Thread Arnaud Delobelle
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Fri, 21 Nov 2008 17:26:21 +, Arnaud Delobelle wrote: > > [...] >> As classes can be decorated in Python 3, you can write a decorator to >> make a class totally ordered. Here is a very simplified proof of >&

Re: Python 3 __cmp__ semantic change?

2008-11-22 Thread Arnaud Delobelle
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Sat, 22 Nov 2008 08:27:59 +, Arnaud Delobelle wrote: > >>>> Granted it's not as efficient as a __cmp__ function. >>> >>> What makes you say that? What do you mean by "efficient"? A

Re: Python 3 __cmp__ semantic change?

2008-11-22 Thread Arnaud Delobelle
Arnaud Delobelle <[EMAIL PROTECTED]> writes: > I haven't done any tests but as Fraction.__gt__ calls *both* > Fraction.__eq__ and Fraction.__lt__ it is obvious that it is going to be > roughly twice as slow. There's a very simple way of emulating Fraction.

Re: complaints about no replies last week

2009-03-30 Thread Arnaud Delobelle
prueba...@latinmail.com writes: [...] > I myself asked about how to write a library to efficiently do union > and intersection of sets containing time intervals some time ago on > this list and got little to no answers. It is a tricky problem. Since > I was getting paid I got an O(n*n) solution wor

Re: complaints about no replies last week

2009-03-31 Thread Arnaud Delobelle
Arnaud Delobelle wrote: > prueba...@latinmail.com writes: > [...] > > I myself asked about how to write a library to efficiently do union > > and intersection of sets containing time intervals some time ago on > > this list and got little to no answers. It is a tricky

Re: complaints about no replies last week

2009-03-31 Thread Arnaud Delobelle
prueba...@latinmail.com writes: [...] > Well since I attracted a couple people's attention I will describe the > problem in more detail. Describing the problem properly is probably as > hard as solving it, so excuse me if I struggle a bit. > > The problem is for a health insurance company and invol

Re: complaints about no replies last week

2009-03-31 Thread Arnaud Delobelle
a...@pythoncraft.com (Aahz) writes: > Arnaud Delobelle wrote: >> >>There are no comments - I don't have the time to add any, sorry! > > The margin is too small to contain the proof? I wish I could come up with such a resilient conjecture! Ah but in this case, the p

Re: python for loop

2009-04-01 Thread Arnaud Delobelle
Lada Kugis writes: > I'm coming from fortran and c background so I'm certainly biased by > them. But if you could explain one thing to me: > > in fortran for example: > for i=1,n > goes from 1,2,3,4,...,n > > in python for example: > for i in range(1,n) > goes from 1,2,3,4,...,n-1 > (that is, it

Re: python for loop

2009-04-02 Thread Arnaud Delobelle
Carl Banks wrote: > On Apr 1, 2:32 pm, Arnaud Delobelle wrote: Check the date on the line above (and the PS in that post). > > If I were your boss and you ever pulled something like this, your ass > would be so fired. > > This is unforgiveable, not only changing the ind

Re: python for loop

2009-04-02 Thread Arnaud Delobelle
Steven D'Aprano wrote: > In set theory, you start by defining the integers like this: > > 0 is the cardinality (size) of the empty set, the set with nothing in it. > > 1 is the cardinality of the set of empty sets, that is, the set > containing nothing but the empty set. > > 2 is the cardinality o

Re: simple iterator question

2009-04-02 Thread Arnaud Delobelle
Neal Becker writes: > How do I interleave 2 sequences into a single sequence? Here's a way: >>> a = [1,2,3,4] >>> b = [5,6,7,8] >>> [x for S in zip(a, b) for x in S] [1, 5, 2, 6, 3, 7, 4, 8] > How do I interleave N sequences into a single sequence? In the same way as above. -- Arnaud -- htt

Re: Generators/iterators, Pythonicity, and primes

2009-04-11 Thread Arnaud Delobelle
John Posner writes: > Inspired by recent threads (and recalling my first message to Python > edu-sig), I did some Internet searching on producing prime numbers using > Python generators. Most algorithms I found don't go for the infinite, > contenting themselves with "list all the primes below a g

Re: Q:Pythonic way to create list of lists

2009-04-12 Thread Arnaud Delobelle
grkunt...@gmail.com writes: > I am just learning Python. > > I am trying to create a list of empty lists: [[], [], [], ...] (10 > items total). > > What is the most Pythonic way to do this? > > If I use a list comprehension (as in myList = [[] for item in xrange > (0, 10)]), Netbeans warns me that

Re: Generators/iterators, Pythonicity, and primes

2009-04-12 Thread Arnaud Delobelle
Duncan Booth writes: > John Posner wrote: > >> Do know what in the itertools implementation causes adding a 'if p <= >> sqrt(n)' clause to *decrease* performance, while adding a >> 'takewhile()' clause *increases* performance? > > I haven't timed it, but I would guess that the takewhile was fas

Re: any(), all() and empty iterable

2009-04-12 Thread Arnaud Delobelle
Paul Rubin writes: > Tim Chase writes: >> > Return True if all elements of the iterable are >> > true. ... >> Then I'd say the comment is misleading. An empty list has no item >> that is true (or false), yet it returns true. > > The comment is corr

Re: any(), all() and empty iterable

2009-04-12 Thread Arnaud Delobelle
Tim Chase writes: > Arnaud Delobelle wrote: >> Paul Rubin <http://phr...@nospam.invalid> writes: >> >>> Tim Chase writes: >>>>> Return True if all elements of the iterable are >>>>> true. ... >>>> Then I&

Re: Generators/iterators, Pythonicity, and primes

2009-04-12 Thread Arnaud Delobelle
Duncan Booth writes: > Duncan Booth wrote: > >> John Posner wrote: >> >>> Do know what in the itertools implementation causes adding a 'if p <= >>> sqrt(n)' clause to *decrease* performance, while adding a >>> 'takewhile()' clause *increases* performance? >> >> I haven't timed it, but I woul

Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread Arnaud Delobelle
Arnaud Delobelle writes: > binops = ['add', 'sub', 'mul', 'div', 'radd', 'rsub'] # etc > unops = ['neg', 'abs', invert'] # etc Oops. There's a missing quote above. It should have been, of

Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread Arnaud Delobelle
Steven D'Aprano writes: > I have a subclass of int where I want all the standard arithmetic > operators to return my subclass, but with no other differences: > > class MyInt(int): > def __add__(self, other): > return self.__class__(super(MyInt, self).__add__(other)) > # and so on

Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread Arnaud Delobelle
"andrew cooke" writes: > Arnaud Delobelle wrote: >> I do this: >> >> binops = ['add', 'sub', 'mul', 'div', 'radd', 'rsub'] # etc >> unops = ['neg', 'abs', invert'] # etc &

Re: any(), all() and empty iterable

2009-04-14 Thread Arnaud Delobelle
Tim Chase writes: > Peter Pearson wrote: >> On Sun, 12 Apr 2009 06:53:24 -0500, Tim Chase wrote: >From the docs: all(iterable) Return True if all elements of the iterable are true. Equivalent to: def all(iterable):

Re: how to know argument name with which a function of extended c called

2009-04-14 Thread Arnaud Delobelle
rahul writes: > Hi, > i need to write a 'c extension function' in this function i need to > change argument value with which this function called. > ie, > if a python code like > import changeValue as c > arg="old value" > c.changeValue(arg) >

Re: Modifying the value of a float-like object

2009-04-15 Thread Arnaud Delobelle
eric.le.bi...@spectro.jussieu.fr writes: > As for your idea of "straight-forward interval arithmetic", it's a > good one, but I'd have to redefine lots of functions from the math > module, to use them explicitly in my code, etc.: this is heavy; I was > looking for a light-weight alternative, where

Re: Modifying the value of a float-like object

2009-04-15 Thread Arnaud Delobelle
eric.le.bi...@spectro.jussieu.fr writes: > Arnaud, your code is very interesting! > > On Apr 15, 1:00 pm, Arnaud Delobelle wrote: >> I still don't understand why you need mutable floats. > > Here is why: the code that your proposed (or any code that does > straightf

Re: How to check all elements of a list are same or different

2009-04-16 Thread Arnaud Delobelle
Piet van Oostrum writes: >> John Machin (JM) wrote: > >>JM> On Apr 16, 8:14 am, Chris Rebert wrote: def all_same(lst):     return len(set(lst)) == 1 def all_different(lst):     return len(set(lst)) == len(lst) > >>JM> @ OP: These are very reasonable interpret

Re: script question

2009-04-17 Thread Arnaud Delobelle
"D'Arcy J.M. Cain" writes: > On 17 Apr 2009 07:03:18 -0700 > a...@pythoncraft.com (Aahz) wrote: >> Go to all that trouble, you might as well make it easier: >> >> for func in funclist: >> func() > > And if you need the return values: > > retlist = [func() for func in funclist] And if yo

Re: Is there a programming language that is combination of Python and Basic?

2009-04-17 Thread Arnaud Delobelle
baykus writes: > Hi > > I am looking for one of those experimental languages that might be > combination of python+basic. Now thta sounds weird and awkward I know. > The reason I am asking is that I always liked how I could reference- > call certain line number back in the days. It would be inter

Re: question about xrange performance

2009-04-18 Thread Arnaud Delobelle
Steven D'Aprano writes: [...] > Speaking about idiomacy, it is grammatically incorrect to start sentences > in English with lower-case letters [...] [...] > > x.0 floats working with xrange is an accident, not a deliberate design > decision, and has been deprecated in Python 2.6, which means it

Re: sorting two corresponding lists?

2009-04-20 Thread Arnaud Delobelle
Esmail writes: > Hello all, > > I wonder if someone could help me with sorting two corresponding lists. > > For instance the first list contains some items, and the second list > contains their value (higher is better) > > items = [apple, car, town, phone] > values = [5, 2, 7, 1] > > I would like

Re: generating random tuples in python

2009-04-20 Thread Arnaud Delobelle
per writes: > hi all, > > i am generating a list of random tuples of numbers between 0 and 1 > using the rand() function, as follows: > > for i in range(0, n): > rand_tuple = (rand(), rand(), rand()) > mylist.append(rand_tuple) > > when i generate this list, some of the random tuples might be

Re: pylab quick reference? (matplotlib)

2009-04-22 Thread Arnaud Delobelle
Esmail writes: > norseman wrote: >> >> Just out of curiosity, have you tried: >> >> import pylab >> help(pylab) >> >> The next step is to print it, > > Ah .. I didn't know this, great idea. This is what I used to get > the contents into a file for printing > > python -c 'import pylab; help(py

Re: Strange problem when using imp.load_module

2009-04-23 Thread Arnaud Delobelle
pythoncuri...@gmail.com writes: > Hi, Hi, I have a guess at explaining the behaviour you describe - see below. > I'm having problem when I'm trying to import modules using the > imp.load_module function. > At the end of this post there's some code I wrote to illustrate the > problem. > The code

Re: sorting two corresponding lists?

2009-04-24 Thread Arnaud Delobelle
On Apr 24, 2:32 am, "Hans DushanthaKumar" wrote: > Just being pedantic here :) > > [items[x] for x in [i for i in map(values.index, new_values)]] > > Is the same as > > [items[x] for x in map(values.index, new_values)] It's also the same as [items[x] for x in [values.index(i) for i in new_va

Re: best way to compare contents of 2 lists?

2009-04-24 Thread Arnaud Delobelle
On Apr 24, 7:12 am, bearophileh...@lycos.com wrote: [...] > Another solution is to use frequency dicts, O(n): > > from itertools import defaultdict > d1 = defaultdict(int) > for el in a: >     d1[el] += 1 > d2 = defaultdict(int) > for el in b: >     d2[el] += 1 > d1 == d2 Thanks to the power of ne

Re: Superclass initialization

2009-04-24 Thread Arnaud Delobelle
On Apr 24, 3:04 pm, Ole Streicher wrote: > Hi again, > > I am trying to initialize a class inherited from numpy.ndarray: > > from numpy import ndarray > > class da(ndarray): >     def __init__(self, mydata): >         ndarray.__init__(self, 0) >         self.mydata = mydata > > When I now call the

Re: Superclass initialization

2009-04-24 Thread Arnaud Delobelle
On Apr 24, 3:46 pm, Ole Streicher wrote: > Arnaud Delobelle writes: > > numpy.ndarray has a __new__ method (and no __init__).  I guess this is > > the one you should override.  Try: > > What is the difference? > > best regards > > Ole Here's an explanatio

Re: python list handling and Lisp list handling

2009-04-24 Thread Arnaud Delobelle
Mark Tarver writes: > Ah; so this > > def cons (x,y): > return [x] + y > > is not accurate? Depends what you mean by accurate! in lisp, if you do: (setq a '(1 2)) (setq b (cons 0 a)) (rplaca a 3) Then a is now (3 2) b is now (0 3 2) In Python, if you do: a = [1

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Arnaud Delobelle
namekuseijin writes: > Ciprian Dorin, Craciun wrote: >> On Sun, Apr 26, 2009 at 7:54 AM, Steven D'Aprano >> wrote: >> I liked very much your implementation for the compare function, it >> is very short and at the same time readable: >> >>> def compare(a, b, comp=operator.eq): >>> return

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Arnaud Delobelle
Paul Rubin writes: > namekuseijin writes: >> ... return (len(a) == len(b)) and not any(not comp(a,b) for (a,b) >> in (zip(a, b))) > > If I'm reading that correctly, I think I'd write it as: > > from itertools import imap, izip > return (len(a) == l

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Arnaud Delobelle
bearophileh...@lycos.com writes: > You can also use quite less code, but this is less efficient: > > def equal_items(iter1, iter2, key=lambda x: x): > class Guard(object): pass > try: > for x, y in izip_longest(iter1, iter2, fillvalue=Guard()): > if key(x) != key(y): >

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Arnaud Delobelle
Arnaud Delobelle writes: > Another way would be: > > def equal_items(iter1, iter2, key=lambda x: x): > iter1, iter2 = iter(iter1), iter(iter2) > for x, y in izip(iter1, iter2): > if key(x) != key(y): > return False > for x, y in i

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Arnaud Delobelle
Peter Otten <__pete...@web.de> writes: > Arnaud Delobelle wrote: > >> def equal_items(iter1, iter2, key=lambda x: x): >>     iter1, iter2 = iter(iter1), iter(iter2) >>     for x, y in izip(iter1, iter2): >>         if key(x) != key(y): >>             re

Re: Into itertools

2009-04-26 Thread Arnaud Delobelle
AggieDan04 writes: > Good suggestions. Another useful function I'd like to see in > itertools is the Cartesian product. This can be implemented as: [snip implementation] You mean itertools.product? http://docs.python.org/library/itertools.html#itertools.product -- Arnaud -- http://mail.pyt

Re: and [True,True] --> [True, True]?????

2009-04-26 Thread Arnaud Delobelle
John Posner writes: > jazbees wrote: > >> I'm surprised to see that the use of min and max for element-wise >> comparison with lists has not been mentioned. When fed lists of True/ >> False values, max will return True if there is at least one True in >> the list, while min will return False if

Re: question about class vs class at

2009-04-26 Thread Arnaud Delobelle
grocery_stocker writes: > When I do pexpect.spawn in the following example, I see 'pexpect.spawn'> > > [cdal...@localhost oakland]$ python > Python 2.4.3 (#1, Oct 1 2006, 18:00:19) > [GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2 > Type "help", "copyright", "credits" or "license" for more in

Re: Into itertools

2009-04-27 Thread Arnaud Delobelle
On 26 Apr, 17:32, bearophileh...@lycos.com wrote: > Some idioms are so common that I think they deserve to be written in C > into the itertools module. > > 1) leniter(iterator) [...] > A Python implementation: > > def leniter(iterator): >     if hasattr(iterator, "__len__"): >         return len(it

Re: Best way to evaluate boolean expressions from strings?

2009-04-28 Thread Arnaud Delobelle
Gustavo Narea writes: > Hello, everybody. > > I need to evaluate boolean expressions like "foo == 1" or "foo ==1 and > (bar > 2 or bar == 0)" which are defined as strings (in a database or > a plain text file, for example). How would you achieve this? > > These expressions will contain placeholde

Re: Python Noob - a couple questions involving a web app

2009-04-28 Thread Arnaud Delobelle
"Kyle T. Jones" writes: > Been programming for a long time, but just starting out with > Python. Not a professional programmer, just that guy in one of those > organizations that won't hire a pro, instead saying "Hey, Kyle knows > computer stuff - let's have him do this (and that, and the other,

Re: complementary lists?

2009-04-28 Thread Arnaud Delobelle
Kay Schluehr writes: > On 29 Apr., 05:41, Ross wrote: >> If I have a list x = [1,2,3,4,5,6,7,8,9] and another list that is a >> subset of x: y = [1,4,7] , is there a quick way that I could return >> the complementary subset to y z=[2,3,5,6,8,9] ? >> >> The reason I ask is because I have a g

Re: import and package confusion

2009-04-29 Thread Arnaud Delobelle
Dale Amon writes: > I do not really see any other way to do what I want. If > there is a way to get rid of the exec in the sample code > I have used, I would love to know... but I can't see how > to import something where part of the name comes from user > command line input without interpreting

Re: using zip() and dictionaries

2009-04-30 Thread Arnaud Delobelle
Sneaky Wombat writes: > I'm really confused by what is happening here. If I use zip(), I > can't update individual dictionary elements like I usually do. It > updates all of the dictionary elements. It's hard to explain, so here > is some output from an interactive session: > > In [52]: header

Re: import and package confusion

2009-04-30 Thread Arnaud Delobelle
Dale Amon writes: > Now I can move on to parsing those pesky Fortran card > images... There wouldn't happen to be a way to take n > continguous slices from a string (card image) where each > slice may be a different length would there? Fortran you > know. No spaces between input fields. :-) > >

Re: list comprehension question

2009-04-30 Thread Arnaud Delobelle
Ross writes: > If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to > return a new list of each individual element in these tuples, I can do > it with a nested for loop but when I try to do it using the list > comprehension b = [j for j in i for i in a], my output is b = > [5,5,5,6

Re: list comprehension question

2009-05-01 Thread Arnaud Delobelle
Emile van Sebille writes: > On 5/1/2009 7:31 AM J Kenneth King said... >> Chris Rebert writes: >>> b = [] >>> for pair in a: >>> for item in pair: >>> b.append(item) >> >> This is much more clear than a nested comprehension. >> >> I love comprehensions, but abusing them can lead to r

Re: list comprehension question

2009-05-01 Thread Arnaud Delobelle
Emile van Sebille writes: > On 5/1/2009 9:19 AM Arnaud Delobelle said... >> Emile van Sebille writes: >>> On 5/1/2009 7:31 AM J Kenneth King said... >>>> I love comprehensions, but abusing them can lead to really dense and >>>> difficult to read c

Re: Why bool( object )?

2009-05-02 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Fri, 01 May 2009 15:03:30 -0700, Aaron Brady wrote: > >> On May 1, 4:30 am, Steven D'Aprano > cybersource.com.au> wrote: >>> On Fri, 01 May 2009 16:30:19 +1200, Lawrence D'Oliveiro wrote: >>> > I have never written anything so unbelievable in my life. And I hope >>> >

Re: eval(WsgiApplication)

2009-05-02 Thread Arnaud Delobelle
gert writes: > I would like to read the following from a text file > > from json import loads > from gert.db import Db > def application(environ, response): > v = loads(environ['wsgi.input'].read(int(environ > ['CONTENT_LENGTH'])).decode('utf-8')) > db = Db() > db.execute('UPDATE vote

Re: Warning of missing side effects

2009-05-02 Thread Arnaud Delobelle
Dave Angel writes: > Python allows multiple assignments in the same statement, but they're > all to the same object. Unless they are to different objects: a, b = 1, 2 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: for with decimal values?

2009-05-02 Thread Arnaud Delobelle
Esmail writes: > Hello all, > > Is there a Python construct to allow me to do something like > this: > >for i in range(-10.5, 10.5, 0.1): > ... > > If there is such a thing already available, I'd like > to use it, otherwise I can write a function to mimic this, > but I thought I'd check

Re: Help! Can't get program to run.

2009-05-02 Thread Arnaud Delobelle
seanm...@gmail.com writes: > sean-marimpietris-computer:~ seanmarimpietri$ python > Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin > Type "help", "copyright", "credits" or "license" for more information. python module1.py > File ""

Re: Self function

2009-05-03 Thread Arnaud Delobelle
bearophileh...@lycos.com writes: > Sometimes I rename recursive functions, or I duplicate&modify them, > and they stop working because inside them there's one or more copy of > their old name. > This happens to me more than one time every year. > So I have written this: > > from inspect import get

Re: yet another list comprehension question

2009-05-04 Thread Arnaud Delobelle
Snorri H writes: > On May 3, 6:13 am, Ross wrote: >> I'm trying to set up a simple filter using a list comprehension. If I >> have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)] >> and I wanted to filter out all tuples containing None, I would like to >> get the new list b = [(

Re: Self function

2009-05-04 Thread Arnaud Delobelle
bearophileh...@lycos.com writes: > Steve Howell: >>two methods with almost identical names, where one function is the >>public interface and then another method that does most of the >>recursion.< > > Thanks Guido & Walter both Python and D support nested functions, so > in such situations I put t

Re: Personal recommendations for Python and Django on-boarding materials

2009-05-04 Thread Arnaud Delobelle
Grant Rettke writes: > Hi folks, > > From one developer to another, I am looking for some personal > recommendations on what are the best materials for fast tracking an on- > boarding to Python and Django. > > I know how to program, get web apps and OO; this is the audience. > > I have found some

Re: Self function

2009-05-04 Thread Arnaud Delobelle
bearophileh...@lycos.com writes: > Aahz: >> When have you ever had a binary tree a thousand levels deep? > > Yesterday. > > >>Consider how big 2**1000 is...< > > You are thinking just about complete binary trees. > But consider that a topology like a single linked list (every node has > 1 child, a

Re: Self function

2009-05-05 Thread Arnaud Delobelle
On 5 May, 07:08, Steven D'Aprano wrote: > On Mon, 04 May 2009 17:54:50 -0400, Terry Reedy wrote: > > bearophileh...@lycos.com wrote: > > >> Another possible syntax: > > >> def fact(n): > >>     return 1 if n <= 1 else n * return(n - 1) > > >> But I guess most people don't see this problem as impor

Re: Self function

2009-05-05 Thread Arnaud Delobelle
On 5 May, 13:33, Luis Zarrabeitia wrote: > On Tuesday 05 May 2009 02:46:58 am Chris Rebert wrote: > > > > > Adding syntax is EVIL(tm) for it angers the Gods of Backwards > > Compatibility, and this proposal is completely unnecessary because you > > could instead just write: > [...] > > And there

Re: call function of class instance with no assigned name?

2009-05-05 Thread Arnaud Delobelle
Chris Rebert writes: > On Tue, May 5, 2009 at 8:52 AM, George Oliver > wrote: >> hi, I'm a Python beginner with a basic question. I'm writing a game >> where I have keyboard input handling defined in one class, and >> command execution defined in another class. The keyboard handler >> class con

Re: Self function

2009-05-06 Thread Arnaud Delobelle
On May 5, 10:20 pm, Aaron Brady wrote: > def auto( f ): >     def _inner( *ar, **kw ): >         return f( _inner, *ar, **kw ) >     return _inner Quoting myself near the start of this thread: Here's an idea: >>> def bindfunc(f): ... def boundf(*args, **kwargs): ... return f(boundf,

<    2   3   4   5   6   7   8   9   10   11   >