Re: Test None for an object that does not implement ==

2011-12-24 Thread Paul Rubin
GZ writes: > assert (a==None)==(c==None)... > So how do I reliably test if a value is None or not? Equality is the wrong comparison to start with. Use "a is None". -- http://mail.python.org/mailman/listinfo/python-list

Test None for an object that does not implement ==

2011-12-24 Thread GZ
Hi, I run into a weird problem. I have a piece of code that looks like the following: f(, a=None, c=None): assert (a==None)==(c==None) The problem is that == is not implemented sometimes for values in a and c, causing an exception NotImplementedError. I ended up doing assert (not a)==

installing matplotlib in MacOs 10.6.8.

2011-12-24 Thread Alex Ter-Sarkissov
hi everyone, I run python 2.7.2. in Eclipse (recently upgraded from 2.6). I have a problem with installing matplotlib (I found the version for python 2.7. MacOs 10.3, no later versions). If I run python in terminal using arch -i386 python, and then from matplotlib.pylab import * and similar stuff

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread Lie Ryan
On 12/24/2011 07:25 PM, Steven D'Aprano wrote: I'd use a function attribute. def func(x, y=None): if y is None: y = func.default_y ... func.default_y = [] That's awkward only if you believe function attributes are awkward. I do. All you've done is move the default from *before* the

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread rusi
On Dec 25, 5:32 am, Devin Jeanpierre wrote: > alex23 wrote: > > Because I believe that the source of confusion has far more to do with > > mutable/immutable objects than with early/late binding. Masking or > > 'correcting' an aspect of Python's behaviour because novices make the > > wrong assumpti

Re: Adding an interface to existing classes

2011-12-24 Thread Terry Reedy
On 12/24/2011 6:49 PM, Spencer Pearson wrote: On Dec 23, 9:13 am, Terry Reedy wrote: On 12/22/2011 3:21 AM, Spencer Pearson wrote: I'm writing a geometry package, with Points and Lines and Circles and so on, and eventually I want to be able to draw these things on the screen. I have two optio

Re: Adding an interface to existing classes

2011-12-24 Thread Rick Johnson
On Dec 22, 2:21 am, Spencer Pearson wrote: > I'm writing a geometry package, with Points and Lines and Circles and > so on, and eventually I want to be able to draw these things on the > screen. ...which is the main reason for creating a geometry package in the first place!. I mean, imaginary poi

Re: Adding an interface to existing classes

2011-12-24 Thread Ian Kelly
On Thu, Dec 22, 2011 at 1:21 AM, Spencer Pearson wrote: > I see a problem with this, though. The intersection of two lines is > (usually) an object of type Point. Since DrawableLine inherits from > Line, this means that unless I redefine the "intersect" method in > DrawableLine, the intersection o

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Rick Johnson
On Dec 24, 6:24 pm, alex23 wrote: > That you're a condescending douchebag with nothing of value to > contribute? > > Crystal. Take it from me Eelco. Once Alex drops into your thread and starts name calling, it's over my friend. -- http://mail.python.org/mailman/listinfo/python-list

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread Devin Jeanpierre
> Because I believe that the source of confusion has far more to do with > mutable/immutable objects than with early/late binding. Masking or > 'correcting' an aspect of Python's behaviour because novices make the > wrong assumption about it just pushes the problem elsewhere and > potentially makes

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread alex23
On Dec 25, 12:39 am, Eelco wrote: > This is really going to be the last time I waste any words on this Oh hey, don't feel you actually have to justify the bullshit you're talking for my sake. > In case of python, collection PACKING (not unpacking) is signaled by a > construct that can be viewed

Re: Adding an interface to existing classes

2011-12-24 Thread Spencer Pearson
On Dec 23, 9:13 am, Terry Reedy wrote: > On 12/22/2011 3:21 AM, Spencer Pearson wrote: > > > I'm writing a geometry package, with Points and Lines and Circles and > > so on, and eventually I want to be able to draw these things on the > > screen. I have two options so far for how to accomplish thi

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread alex23
On Dec 25, 9:25 am, Devin Jeanpierre wrote: > > If Python was ever 'fixed' to prevent this issue, I'm pretty sure we'd > > see an increase in the number of questions like the OP's. > > What makes you so sure? Both models do make sense and are equally > valid, it's just that only one of them is tru

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread Devin Jeanpierre
> If Python was ever 'fixed' to prevent this issue, I'm pretty sure we'd > see an increase in the number of questions like the OP's. What makes you so sure? Both models do make sense and are equally valid, it's just that only one of them is true. Is it just because people already used to Python wo

Re: Generator Question

2011-12-24 Thread GZ
I see. Thanks for the clarification. On Dec 22, 12:35 am, Steven D'Aprano wrote: > On Wed, 21 Dec 2011 21:45:13 -0800, GZ wrote: > > Now the question here is this: > > > def h(): > >     if condition=true: > >        #I would like to return an itereator with zero length > >     else: > >        f

Is my IDLE problem caused by .idlerc? Permissions.

2011-12-24 Thread W. eWatson
I installed 64-bit Python 2.7.2 on Win 7. IDLE does appear as the second choice on right-click of a py file menu. However, nothing happens if I use it. If I try to execute idle from the cmd window, it complains about .idlerc\recent-files.lst IOError: [Errno 13] Permission denied: 'C:\\Users\\

Re: How to check for single character change in a string?

2011-12-24 Thread Rick Johnson
On Dec 24, 11:09 am, Arnaud Delobelle wrote: > sum(map(str.__ne__, str1, str2)) Mirror, mirror, on the wall. Who's the cleanest of them all? -- http://mail.python.org/mailman/listinfo/python-list

Re: what does 'a=b=c=[]' do

2011-12-24 Thread Thomas Rachel
Am 22.12.2011 00:20 schrieb Dennis Lee Bieber: The key one is that lists ([] defines a list, not an array) are "mutable". Your "7" is not mutable. Strictly spoken, that's only a "side show" where the effect is visible. The real key concept is that [] creates *one* object which is then

Re: what does 'a=b=c=[]' do

2011-12-24 Thread Thomas Rachel
Am 22.12.2011 00:48 schrieb Steven D'Aprano: On Wed, 21 Dec 2011 18:20:16 -0500, Dennis Lee Bieber wrote: For the amount of typing, it's easier to just do a straight line tuple unpack a,b,c = ([],[],[]) Note that tuples are created by the comma, not the round brackets (or parenthese

Re: what does 'a=b=c=[]' do

2011-12-24 Thread Thomas Rachel
Am 21.12.2011 23:25 schrieb Eric: Is it true that if I want to create an array or arbitrary size such as: for a in range(n): x.append() I must do this instead? x=[] for a in range(n): x.append() Of course - your x must exist before using it. > Now to my actual quest

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Chris Angelico
On Sun, Dec 25, 2011 at 4:23 AM, Eelco wrote: > Thats not a fair point, but more nitpicking. Yes, I should have been > more precise: in python, 'whitespace' is not a single beast like in > most languages, but newlines have a special meaning. I was obviously > not talking about those. Want to try a

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Eelco
On Dec 24, 4:01 pm, Chris Angelico wrote: > On Sun, Dec 25, 2011 at 1:45 AM, Eelco wrote: > > Can you give an example of a construct in python where two whitespace > > delimited identifiers are legal? > > What do you mean? Two identifiers, separated only by whitespace and no > keyword or operator

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Eelco
On Dec 24, 3:57 pm, Chris Angelico wrote: > On Sun, Dec 25, 2011 at 1:47 AM, Eelco wrote: > > a, middle::tuple, b = ::sequence > > Then it ought to be > > ::(a, middle::tuple, b) = ::sequence > > or something, because you're doing the same thing on both sides. > > ChrisA Thats a fair point; some

Re: How to check for single character change in a string?

2011-12-24 Thread Arnaud Delobelle
On 24 December 2011 16:10, Roy Smith wrote: > In article , >  Roy Smith wrote: > >> >>> len([x for x in zip(s1, s2) if x[0] != x[1]]) > > Heh, Ian Kelly's version: > >> sum(a == b for a, b in zip(str1, str2)) > > is cleaner than mine.  Except that Ian's counts matches and the OP asked > for non-m

Re: How to check for single character change in a string?

2011-12-24 Thread Roy Smith
In article , Roy Smith wrote: > >>> len([x for x in zip(s1, s2) if x[0] != x[1]]) Heh, Ian Kelly's version: > sum(a == b for a, b in zip(str1, str2)) is cleaner than mine. Except that Ian's counts matches and the OP asked for non-matches, but that's an exercise for the reader :-) -- http:/

Re: How to check for single character change in a string?

2011-12-24 Thread Roy Smith
In article , tinn...@isbd.co.uk wrote: > Can anyone suggest a simple/easy way to count how many characters have > changed in a string? Depending on exactly how you define "changed", you're probably talking about either Hamming Distance or Levenshtein Distance. I would start with the wikipedia

Re: How to check for single character change in a string?

2011-12-24 Thread Ian Kelly
On Sat, Dec 24, 2011 at 8:26 AM, wrote: > Can anyone suggest a simple/easy way to count how many characters have > changed in a string? > > E.g. giving results as follows:- > >    abcdefg     abcdefh         1 >    abcdefg     abcdekk         2 >    abcdefg     gfedcba         6 > > > Note that p

How to check for single character change in a string?

2011-12-24 Thread tinnews
Can anyone suggest a simple/easy way to count how many characters have changed in a string? E.g. giving results as follows:- abcdefg abcdefh 1 abcdefg abcdekk 2 abcdefg gfedcba 6 Note that position is significant, a character in a different positi

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Chris Angelico
On Sun, Dec 25, 2011 at 1:45 AM, Eelco wrote: > Can you give an example of a construct in python where two whitespace > delimited identifiers are legal? What do you mean? Two identifiers, separated only by whitespace and no keyword or operator? def foo(): asdf qwer Perfectly legal, two

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Chris Angelico
On Sun, Dec 25, 2011 at 1:47 AM, Eelco wrote: > a, middle::tuple, b = ::sequence Then it ought to be ::(a, middle::tuple, b) = ::sequence or something, because you're doing the same thing on both sides. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Eelco
On Dec 22, 2:12 pm, Steven D'Aprano wrote: > On Thu, 22 Dec 2011 06:49:16 -0500, Neal Becker wrote: > > I agree with the OP that the current syntax is confusing.  The issue is, > > the meaning of * is context-dependent. > > Here you are complaining about an operator being "confusing" because it >

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Eelco
On Dec 20, 6:47 am, Steven D'Aprano wrote: > On Mon, 19 Dec 2011 19:35:20 -0800, alex23 wrote: > > Eelco wrote: > >> Having two seperate symbols seperated by whitespace, as in @list args > >> strikes me as a terrible break of normal python lexical rules. > > > You mean like 'is not'? And the upco

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Eelco
On Dec 20, 4:35 am, alex23 wrote: > Eelco wrote: > > Having two seperate symbols seperated by whitespace, as in @list args > > strikes me as a terrible break of normal python lexical rules. > > You mean like 'is not'? And the upcoming 'yield from'? Im not sure why, but this feels like something

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Eelco
On Dec 21, 4:48 pm, Neal Becker wrote: > Clarification: where can packing/unpacking syntax be used? > > It would be great if it were valid essentially anywhere (not limited to > parameter passing). > > What about constructs like: > > a, @tuple tail, b = sequence? This has come up many times in th

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-24 Thread Eelco
On Dec 20, 4:30 am, alex23 wrote: > On Dec 19, 8:15 pm, Eelco wrote: > > > What does that have to do with collection packing/unpacking? > > It's mocking your insistance that collection unpacking is a type > constraint. This is really going to be the last time I waste any words on this: The sent

[ANN] pyspread 0.2.0

2011-12-24 Thread Martin Manns
== pyspread 0.2.0 == Pyspread 0.2.0 has been released. The new version is an almost complete rewrite for better stability and maintainability. About pyspread == Pyspread is a non-traditional spreadsheet application that is based on and written in Python. P

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread alex23
On Dec 24, 6:25 pm, Steven D'Aprano wrote: > > It's > > much harder to figure out what's going wrong with an early-bound > > mutable. > > Only for those who don't understand, or aren't thinking about, Python's > object model. The behaviour of early-bound mutables is obvious and clear > once you th

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread alex23
On Dec 24, 2:15 am, Roy Smith wrote: > I know this is not quite the same thing, but it's interesting to look at > what django (and mongoengine) do in their model definitions, prompted by > your time.time() example.  You can do declare a model field something > like: > > class Foo(models.Model): >

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread alex23
On Dec 24, 2:27 am, Mel Wilson wrote: > In a tool that's meant for other people to use to accomplish work of their > own, breaking workflow is a cardinal sin. > > In a research language that's meant always to be up-to-date with the concept > of the week, not so much. What on earth gave you the im

Re: what does 'a=b=c=[]' do

2011-12-24 Thread Lie Ryan
On 12/22/2011 10:20 AM, Dennis Lee Bieber wrote: which is to define the names "a", "b", and "c", and connects the three names to the single object (integer 7 or new empty list). note that this "connects" and "disconnecting" business is more commonly referred to in python parlance as "binding"

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread Steven D'Aprano
On Fri, 23 Dec 2011 19:24:44 -0500, Devin Jeanpierre wrote: >> To fake early binding when the language provides late binding, you >> still use a sentinel value, but the initialization code creating the >> default value is outside the body of the function, usually in a global >> variable: >> >>

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread Steven D'Aprano
On Fri, 23 Dec 2011 17:03:11 +, Neil Cerutti wrote: >> The disadvantage of late binding is that since the expression is live, >> it needs to be calculated each time, even if it turns out to be the >> same result. But there's no guarantee that it will return the same >> result each time: > > T

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-24 Thread Steven D'Aprano
On Sat, 24 Dec 2011 09:50:04 +1100, Chris Angelico wrote: > On Sat, Dec 24, 2011 at 9:32 AM, Steven D'Aprano > wrote: >> Yes. But having to manage it *by hand* is still unclean: > > Well, my point was that Python's current behaviour _is_ that. Minus the managing it by hand part. >> * you stil