Prev: jpeg package
Next: help req setting python executable
From: dmitrey on 2 May 2010 08:11 Python 2.6.5 r265:79063 >>>set().update(set()) is None True while I expect result of update to be set. Also, result of set().add(None) is None while I expect it to be set with element None (or, maybe, it should be empty set?) Regards, D.
From: Aahz on 2 May 2010 08:23 In article <0bd314a8-db65-43f1-a999-521e2ed71cad(a)n15g2000yqf.googlegroups.com>, dmitrey <dmitrey.kroshko(a)scipy.org> wrote: > >Python 2.6.5 r265:79063 >>>>set().update(set()) is None >True >while I expect result of update to be set. >Also, result of >set().add(None) >is None while I expect it to be set with element None (or, maybe, it >should be empty set?) Why are you assuming that your expectations are correct? Generally speaking, Python methods that mutate do *not* return the original object, precisely to make sure you don't make stupid mistakes. You should probably read this: http://www.catb.org/~esr/faqs/smart-questions.html -- Aahz (aahz(a)pythoncraft.com) <*> http://www.pythoncraft.com/ "It is easier to optimize correct code than to correct optimized code." --Bill Harlan
From: Steven D'Aprano on 2 May 2010 09:12 On Sun, 02 May 2010 05:11:40 -0700, dmitrey wrote: > Python 2.6.5 r265:79063 >>>>set().update(set()) is None > True > while I expect result of update to be set. Change your expectations. Generally, methods which modify the object rather than creating a new one return None. >>> s = set([1,2,3]) >>> s.update(set([3, 4, 5])) >>> s {1, 2, 3, 4, 5} > Also, result of set().add(None) is None while I expect it to be set > with element None (or, maybe, it should be empty set?) >>> s = set() >>> s.add(None) >>> s {None} Python sets have been used by tens of thousands of programmers for many years now. Which do you think is more likely? (1) Not one person before you noticed that something as fundamental as adding an item to a set is buggy; or (2) You have misunderstood what is happening? -- Steven
From: Terry Reedy on 2 May 2010 15:23 On 5/2/2010 8:11 AM, dmitrey wrote: > Python 2.6.5 r265:79063 >>>> set().update(set()) is None > True > while I expect result of update to be set. > Also, result of > set().add(None) > is None while I expect it to be set with element None (or, maybe, it > should be empty set?) 'Expect' has two different meanings in this context. 1. The empirical behavior surprised me (because I did not bother to read the manual, which clearly says what the returns are). 2. The documented behavior, which I read, surprises me, because I would have designed things differently, perhaps because I have used other languages designed differently. I am not sure which you meant.
|
Pages: 1 Prev: jpeg package Next: help req setting python executable |