Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Tue, 17 Jul 2012 00:18:28 -0400, Devin Jeanpierre wrote: > On Mon, Jul 16, 2012 at 12:03 AM, Steven D'Aprano > wrote: >> On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: >> >>> For example, instead of "if stack:" or "if bool(stack):", we could use >>> "if stack.isempty():". This lin

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 11:13:33 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: >>> On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: (For the record, I can only think of one trap for the unwary: time objects are false at *ex

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/16/2012 11:39 PM, Steven D'Aprano wrote: > If you need three (or four, or fifty) > distinguishable states, then obviously boolean context will not solve > your problem. I never said it would. That is the impression I got from this statement: > How you interpret some_variable = None depends

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/16/2012 11:11 PM, Steven D'Aprano wrote: > If you are right that SimpleNamespace should be treated as a container, > then it should implement container semantics. Since it doesn't, that is > either: > > 1) a bug; or > 2) a triumph of laziness over correctness > > I imagine though that the

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 20:57:43 -0500, Andrew Berg wrote: > I have a better real example, but I opted not to use it before since it > requires some explanation - IRC messages. A client-to-server message has > the basic form of b'COMMAND arguments :message' (e.g. b'PRIVMSG #channel > :hi guys!'). Some

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Chris Angelico
On Tue, Jul 17, 2012 at 2:18 PM, Ranting Rick wrote: > On Jul 16, 11:11 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: > >> I imagine though that the Python dev's answer will basically be #2: "it >> isn't a container, it just behaves a little bit like a container, except >> when it d

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Devin Jeanpierre
On Mon, Jul 16, 2012 at 12:03 AM, Steven D'Aprano wrote: > On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: > >> For example, instead of "if stack:" or "if bool(stack):", we could use >> "if stack.isempty():". This line tells us explicitly that stack is a >> container. > > isempty is no

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 20:22:18 -0500, Andrew Berg wrote: > On 7/15/2012 3:28 PM, Terry Reedy wrote: >> Because everything does (or should). > I can see how truth testing for empty values is convenient, but perhaps > objects should only have a truth value if explicitly given one - > particularly in c

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Chris Angelico
On Tue, Jul 17, 2012 at 11:57 AM, Andrew Berg wrote: > I could do: > > if has_message: > send('{command} {args} :{message}') > else: > send('{command} {args}') > > but then I'd have to make sure has_message stays accurate since message > won't necessarily be. Or maybe I could leave

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/16/2012 7:43 PM, Steven D'Aprano wrote: > The existence of a jar or no jar is irrelevant to the question of how > many jellybeans there are. They are two different things, and therefore > need two different values. There are many ways to implement this. I have a better real example, but I op

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread rusi
On Jul 15, 9:50 pm, Rick Johnson wrote: > On Sunday, July 15, 2012 11:19:16 AM UTC-5, Ian wrote: > > On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano > > wrote: > > > (For the record, I can only think of one trap for the unwary: time > > > objects are false at *exactly* midnight.) > > > Ugh, that

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/15/2012 3:28 PM, Terry Reedy wrote: > Because everything does (or should). I can see how truth testing for empty values is convenient, but perhaps objects should only have a truth value if explicitly given one - particularly in cases where such a value wouldn't be obvious or the obvious value

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 13:28:14 -0400, Dennis Lee Bieber wrote: > On 16 Jul 2012 02:38:35 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > >> On Sun, 15 Jul 2012 12:02:37 -0500, Andrew Berg wrote: >> >> >> > Okay, I see the value in this, but I don't understand why

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Tue, 17 Jul 2012 01:12:47 +, Steven D'Aprano wrote: > It > looks like Firebird implements the variety of ternary logical called > "Keene logic". Oops, I meant "Kleene". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 13:54:32 -0700, Ethan Furman wrote: > Andrew Berg wrote: >> On 7/15/2012 9:38 PM, Steven D'Aprano wrote: I would expect None to mean "doesn't exist" or "unknown" or something like that - e.g., a value of 0 means 0 jelly beans in the jar and None means there isn't

Re: Diagramming code

2012-07-16 Thread Andrew Cooper
On 16/07/2012 21:41, Andrea Crotti wrote: > On 07/16/2012 02:26 AM, hamilton wrote: >> Is there any software to help understand python code ? >> >> Thanks >> >> hamilton > > Sometimes to get some nice graphs I use gprof2dot > (http://code.google.com/p/jrfonseca/wiki/Gprof2Dot) > or doxygen (http:/

Re: Style question: metaclass self vs cls?

2012-07-16 Thread Terry Reedy
On 7/16/2012 11:29 AM, Steven D'Aprano wrote: Here's a style question for you: in a metaclass, what should I call the instance parameter of methods, "cls" or "self"? class ExampleMeta(type): def method(self, *args): ... I'm not quite sure if that feels right. On the one hand, self is the E

Re: No more Python support in NetBeans 7.0

2012-07-16 Thread trevor . carlston
On Wednesday, October 26, 2011 8:06:16 PM UTC-6, w...@naveed.net wrote: > Sorry to comment on an old topic, but I wanted to clarify for others like me > who might get the wrong idea. > > It looks like this is no longer true. Netbeans 7 might be supporting python > after all. > > http://wiki.ne

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Laszlo Nagy
This syntax is explicit *enough*. We don't need to be any more explicit. But if you are going to argue that "if obj" is *explicit enough*, then apply your argument consistently to "String"+1.75 also. Why must we be explicit about string conversion BUT not boolean conversion? Can you reduce this

Re: No more Python support in NetBeans 7.0

2012-07-16 Thread trevor . carlston
On Wednesday, October 26, 2011 8:06:16 PM UTC-6, w...@naveed.net wrote: > Sorry to comment on an old topic, but I wanted to clarify for others like me > who might get the wrong idea. > > It looks like this is no longer true. Netbeans 7 might be supporting python > after all. > > http://wiki.ne

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Laszlo Nagy
... Traceback (most recent quip last): Author: "", line 7, in LogicalFallacyError: "Reductio ad absurdum" Deary deary me Rick. Reductio ad adsurdum is not a fallacy. It is a counter-argument to an argument or claim, by showing that the premise of the original claim leads to an absurd conc

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Ethan Furman
Andrew Berg wrote: On 7/15/2012 9:38 PM, Steven D'Aprano wrote: I would expect None to mean "doesn't exist" or "unknown" or something like that - e.g., a value of 0 means 0 jelly beans in the jar and None means there isn't a jar. >> How you interpret some_variable = None depends on what some_va

Re: Diagramming code

2012-07-16 Thread Andrea Crotti
On 07/16/2012 02:26 AM, hamilton wrote: Is there any software to help understand python code ? Thanks hamilton Sometimes to get some nice graphs I use gprof2dot (http://code.google.com/p/jrfonseca/wiki/Gprof2Dot) or doxygen (http://www.stack.nl/~dimitri/doxygen/) gprof2dot analyses the out

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/15/2012 9:38 PM, Steven D'Aprano wrote: >> I would expect None to mean "doesn't exist" or "unknown" or >> something like that - e.g., a value of 0 means 0 jelly beans in the jar >> and None means there isn't a jar. > > How you interpret some_variable = None depends on what some_variable > re

Re: Re: PyQt QCalendarWidget events question

2012-07-16 Thread John Posner
On 7/16/2012 12:28 PM, tinn...@isbd.co.uk wrote: > tinn...@isbd.co.uk wrote: >> I am trying to use the PyQt4 calendar widget to perform some different >> actions on specific dates. There are three events available:- >> >> selectionChanged() >> activated(QDate) >> clicked(QDate) >> >> O

Re: Diagramming code

2012-07-16 Thread Miki Tebeka
> Is there any software to help understand python code ? For module dependency you can try http://furius.ca/snakefood/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Diagramming code

2012-07-16 Thread hamilton
Thank you Fred. I am new to python and am reviewing code I find online. Some projects do have docs that spell out what its doing, but many projects that I have download have just the code. I have my own personal style to decypher C and C++ code. But python is still foreign to me. hamilton

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Ethan Furman
Steven D'Aprano wrote: On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: (For the record, I can only think of one trap for the unwary: time objects are false at *exactly* midnight.) >> Ugh, that's irritating. I can't think of any sce

Re: assertraises behaviour

2012-07-16 Thread Peter Otten
andrea crotti wrote: > Good thanks, but there is something that implements this behaviour.. > For example nose runs all the tests, and if there are failures it goes > on and shows the failed tests only in the end, so I think it is > possible to achieve somehow, is that correct? No, I don't see ho

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Albert van der Horst
In article <50038364$0$29995$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: >On Sun, 15 Jul 2012 18:21:06 -0700, Ranting Rick wrote: > >> If HOWEVER we want to "truth test" an object (as in: "if obj") we should >> be FORCED to use the bool! Why? Because explicit is better than implic

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Albert van der Horst
In article , Ranting Rick wrote: >We DON'T want Python to silently convert "cost" to a string. What we >DO want is to force the author to use the str function thereby making >the conversion explicit. We do want Python to silently convert "cost" to a string in the proper context. cost= 3.75 pri

RE: Diagramming code

2012-07-16 Thread Sells, Fred
You leave many relevant questions unanswered. 1. Is the original developer/team available or have you been left with the code and little or no doc's? 2. How big is big in terms of the number of files/modules in the project? 3. Is there a reasonable structure to the project in terms of director

Re: assertraises behaviour

2012-07-16 Thread andrea crotti
Good thanks, but there is something that implements this behaviour.. For example nose runs all the tests, and if there are failures it goes on and shows the failed tests only in the end, so I think it is possible to achieve somehow, is that correct? -- http://mail.python.org/mailman/listinfo/pytho

Re: PyQt QCalendarWidget events question

2012-07-16 Thread tinnews
tinn...@isbd.co.uk wrote: > I am trying to use the PyQt4 calendar widget to perform some different > actions on specific dates. There are three events available:- > > selectionChanged() > activated(QDate) > clicked(QDate) > > On trying all these out it would appear that the event han

PyQt QCalendarWidget events question

2012-07-16 Thread tinnews
I am trying to use the PyQt4 calendar widget to perform some different actions on specific dates. There are three events available:- selectionChanged() activated(QDate) clicked(QDate) On trying all these out it would appear that the event handlers get called as follows:- The cli

Style question: metaclass self vs cls?

2012-07-16 Thread Steven D'Aprano
Here's a style question for you: in a metaclass, what should I call the instance parameter of methods, "cls" or "self"? class ExampleMeta(type): def method(self, *args): ... I'm not quite sure if that feels right. On the one hand, self is the ExampleMeta instance alright... but on the other

Re: assertraises behaviour

2012-07-16 Thread Peter Otten
andrea crotti wrote: > 2012/7/16 Christian Heimes : >> >> The OSError isn't catched as the code never reaches the line with "raise >> OSError". In other words "raise OSError" is never executed as the >> exception raised by "assert False" stops the context manager. >> >> You should avoid testing mo

Re: assertraises behaviour

2012-07-16 Thread andrea crotti
2012/7/16 Christian Heimes : > > The OSError isn't catched as the code never reaches the line with "raise > OSError". In other words "raise OSError" is never executed as the > exception raised by "assert False" stops the context manager. > > You should avoid testing more than one line of code in a

Re: Discussion on some Code Issues

2012-07-16 Thread subhabangalore
On Sunday, July 8, 2012 10:47:00 PM UTC+5:30, Chris Angelico wrote: > On Mon, Jul 9, 2012 at 3:05 AM, wrote: > > On Sunday, July 8, 2012 1:33:25 PM UTC+5:30, Chris Angelico wrote: > >> On Sun, Jul 8, 2012 at 3:42 PM, > wrote: > >> > file_open

Re: Python and Qt4 Designer

2012-07-16 Thread Michael Torrie
On 07/15/2012 01:58 AM, Vincent Vande Vyvre wrote: > Rusi is not the op, and his question is about these lines > > app = None > if ( not app ): Yeah that's a no-op. The original author of that code is clearly confused there. > > not this one > > app = QtGui.QApplication([]) >

Re: assertraises behaviour

2012-07-16 Thread Christian Heimes
Am 16.07.2012 15:38, schrieb andrea crotti: > This small example doesn't fail, but the OSError exception is cathed > even if not declared.. > Is this the expected behaviour (from the doc I would say it's not). > (Running on arch-linux 64 bits and Python 2.7.3, but it doesn the same > with Python 3.

assertraises behaviour

2012-07-16 Thread andrea crotti
I found that the behaviour of assertRaises used as a context manager a bit surprising. This small example doesn't fail, but the OSError exception is cathed even if not declared.. Is this the expected behaviour (from the doc I would say it's not). (Running on arch-linux 64 bits and Python 2.7.3, bu

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Serhiy Storchaka
On 15.07.12 19:50, Rick Johnson wrote: We must NEVER present "if" in such confusing manner as ExampleA. ## EXAMPLE C ## py> if bool(money) == True: ... do_something() -- http://mail.python.org/mailman/listinfo/python-list

Re: unittest: Improve discoverability of discover (Was: Initial nose experience)

2012-07-16 Thread Philipp Hagemeister
On 07/16/2012 02:37 PM, Philipp Hagemeister wrote: > Can we improve the discoverability of the discover > option, for example by making it the default action, or including a > message "use discover to find test files automatically" if there are no > arguments? Oops, already implemented as of Python

Re: Initial nose experience

2012-07-16 Thread Ben Finney
Roy Smith writes: > In article , > pyt...@bdurham.com wrote: > > > After years of using unittest, what would you say are the pros and > > cons of nose? > > BTW, although I'm currently using nose just as a unittest aggregator Be aware that Python 2.7 and higher has unit test discovery in the sta

unittest: Improve discoverability of discover (Was: Initial nose experience)

2012-07-16 Thread Philipp Hagemeister
On 07/16/2012 01:47 PM, Peter Otten wrote: > http://docs.python.org/library/unittest#test-discovery That's precisely it. Can we improve the discoverability of the discover option, for example by making it the default action, or including a message "use discover to find test files automatically" if

Re: Initial nose experience

2012-07-16 Thread Peter Otten
Philipp Hagemeister wrote: > Currently, $ python -m unittest does nothing useful (afaik). Would it > break anything to look in . , ./test, ./tests for any files matching > test_* , and execute those? http://docs.python.org/library/unittest#test-discovery -- http://mail.python.org/mailman/lis

Re: code review

2012-07-16 Thread Ben Finney
Duncan Booth writes: > Technically of course Python doesn't have assignment, it just binds > names. Names, or other references. I'd argue that Python has assignment, and assignment in Python is identical with binding references to objects. But then, the Python documentation refers to “variable

Re: Initial nose experience

2012-07-16 Thread Roy Smith
In article , pyt...@bdurham.com wrote: > After years of using unittest, what would you say are the pros and > cons of nose? BTW, although I'm currently using nose just as a unittest aggregator, I can see some nice advantages to native nose functionality. The most obvious is that tests can be

Re: Initial nose experience

2012-07-16 Thread Philipp Hagemeister
On 07/15/2012 08:58 PM, Roy Smith wrote: >> What motivated you to migrate from unittest to nose? > Mostly I was just looking for a better way to run our existing tests. > We've got a bunch of tests written in standard unittest, but no good way > to start at the top of the tree and run them all w

Re: code review

2012-07-16 Thread Duncan Booth
Steven D'Aprano wrote: > On Fri, 13 Jul 2012 12:30:47 +, Albert van der Horst wrote: >> The worst of is, of course, = for assignment instead of := . This is >> a convention that Python follows, to my dismay. > > *shrug* > > The worst is to use = for both equality and assignment, like some >

Re: Tkinter.event.widget: handler gets name instead of widget.

2012-07-16 Thread Frederic Rentsch
On Sat, 2012-07-14 at 20:10 -0700, rantingrickjohn...@gmail.com wrote: > On Thursday, July 12, 2012 1:53:54 PM UTC-5, Frederic Rentsch wrote: > > > The "hit list" is a table of investment titles (stock, funds, bonds) > > that displays upon entry of a search pattern into a respective template. > >

Re: Diagramming code

2012-07-16 Thread Joel Goldstick
On Mon, Jul 16, 2012 at 3:58 AM, Ulrich Eckhardt wrote: > Am 16.07.2012 03:57, schrieb hamilton: > >> OK then, let me ask, how do you guys learn/understand large projects ? > > > 1. Use the program. This gives you an idea what features are there and a bit > how it could be structured. > 2. Build t

Re: Diagramming code

2012-07-16 Thread Ulrich Eckhardt
Am 16.07.2012 03:57, schrieb hamilton: OK then, let me ask, how do you guys learn/understand large projects ? 1. Use the program. This gives you an idea what features are there and a bit how it could be structured. 2. Build the program, to see what is done to get the program running. This sho

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Sun, 15 Jul 2012 19:41:34 -0700, Ranting Rick wrote: > Short circuitry is a powerful tool! But why the heck would your > sequences ever be None? Are you using None as a default? And if so, why > not use an empty sequence instead ([], {}, "")? Mostly for explicitness. I want to be able to say

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Sun, 15 Jul 2012 22:03:52 -0700, Ranting Rick wrote: > But if you are going to argue that "if obj" is *explicit enough*, then > apply your argument consistently to "String"+1.75 also. Why must we be > explicit about string conversion BUT not boolean conversion? The problem with "String" + 1.75

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread alex23
On Jul 16, 3:03 pm, Ranting Rick wrote: > But if you are going to argue that "if obj" is *explicit enough*, then > apply your argument consistently to "String"+1.75 also. Why must we be > explicit about string conversion BUT not boolean conversion? What _other_ than booleans can you expect a cond

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread alex23
On Jul 16, 2:53 pm, Ranting Rick wrote: > "if obj" is in essence doing "if bool(obj)" behind the scenes. My > question is: Why hide such valuable information from the reader? If @decorator is in essence doing "function = decorator(function)" behind the scenes, why hide that? If classes are just s