Re: [Tutor] IDEs

2010-11-23 Thread Mac Ryan
On Wed, 24 Nov 2010 01:15:48 - "Alan Gauld" wrote: > In a recent project that we > completed we had 600k lines of production code and over a > million lines of test code. > > And we still wound up with over 50 reported bugs during Beta test... > But that was much better than the 2000 bugs on

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread R. Alan Monroe
>>> >> I've always disliked using "if not n % 2"  to test for even/odd ints >>> >> because of its convoluted logic. But I ran some speed tests and found >>> >> it was the way to go over "if n % 2 == 0". >>> > Did you try bitwise-and with 1? >>> What's that? > 2 & 1 >> 0 > 3 & 1 >> 1 >

Re: [Tutor] Help regarding lists, dictionaries and tuples (bob gailer)

2010-11-23 Thread Robert Sjöblom
On Mon, Nov 22, 2010 at 10:27 AM, wrote: > Send Tutor mailing list submissions to >        tu...@python.org > [snip] >> Ok, I'm clearly thinking in circles here. I used the interpreter to >> figure out that both are fine but the first example has integers, >> whereas the second has strings. Good

Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Jose Amoreira
On Tuesday, November 23, 2010 02:01:40 pm Mac Ryan wrote: > The code you wrote generates programs like: > > for l0 in alphabet: > for l1 in alphabet: > for l2 in alphabet: > word = "".join([eval("l"+str(i)) for i in range(n)]) > listOfWords.append(word) > > wh

Re: [Tutor] python script

2010-11-23 Thread Alan Gauld
"Laura Jessen" wrote How would i write a simple python script to issue a scsi inquiry to a drive? Depending on what you want to do and how you define "simple" it may not be possible. If its just to read data from a scsi device then once mounted it should be accesible like any other device.

Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Alan Gauld
"Mac Ryan" wrote I am not 100% sure I got the terms of your problem and I am neither an official tutor of this list, so disregard my comment if it is irrelevant... If you are a member of the list and contribute you are an official tutor. There are no high priests here :-) Alan G. _

Re: [Tutor] IDEs

2010-11-23 Thread Alan Gauld
"Josep M. Fontana" wrote Also, I'm a big believer in test-driven development. I must admit though I'm Does anybody know of any good reference on testing? How do you develop tests for functions? The basic idea in testing is to try to break your code. Try to think of every kind of evil inpu

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Hugo Arts
On Tue, Nov 23, 2010 at 9:52 PM, Wayne Werner wrote: >> > >> > Did you try bitwise-and with 1? >> >> What's that? > 2 & 1 > 0 3 & 1 > 1 10 & 1 > 0 11 & 1 > 0 That last one should be 1, I'd say. ___ Tutor maillist - Tutor@python.org

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Emile van Sebille
On 11/23/2010 1:26 PM Richard D. Moores said... So what's the connection with the tests I've run? It's an even/odd test. [ii&1 for ii in range(1,1000,2)] [ii&1 for ii in range(0,1000,2)] Emile ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Richard D. Moores
On Tue, Nov 23, 2010 at 12:52, Wayne Werner wrote: > On Tue, Nov 23, 2010 at 1:56 PM, Richard D. Moores > wrote: >> >> On Tue, Nov 23, 2010 at 10:29, R. Alan Monroe >> wrote: >> >> I've always disliked using "if not n % 2"  to test for even/odd ints >> >> because of its convoluted logic. But I r

[Tutor] Unsubscribing from mailing lists

2010-11-23 Thread Steven D'Aprano
Wangolo Joel wrote: I NO LONGER WANT YOUR TUTORIAL There's no need to SHOUT. Writing in all-caps is rude. If you don't want these emails, unsubscribe yourself. Just follow the instructions given in every single email: To unsubscribe or change subscription options: http://mail.python.org/

[Tutor] python script

2010-11-23 Thread Laura Jessen
How would i write a simple python script to issue a scsi inquiry to a drive? Laura J. Jessen ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailm

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Wayne Werner
On Tue, Nov 23, 2010 at 1:56 PM, Richard D. Moores wrote: > On Tue, Nov 23, 2010 at 10:29, R. Alan Monroe > wrote: > >> I've always disliked using "if not n % 2" to test for even/odd ints > >> because of its convoluted logic. But I ran some speed tests and found > >> it was the way to go over "i

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Richard D. Moores
On Tue, Nov 23, 2010 at 10:29, R. Alan Monroe wrote: >> I've always disliked using "if not n % 2"  to test for even/odd ints >> because of its convoluted logic. But I ran some speed tests and found >> it was the way to go over "if n % 2 == 0". > > Did you try bitwise-and with 1? What's that? Dic

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread R. Alan Monroe
> I've always disliked using "if not n % 2" to test for even/odd ints > because of its convoluted logic. But I ran some speed tests and found > it was the way to go over "if n % 2 == 0". Did you try bitwise-and with 1? Alan ___ Tutor maillist - Tuto

Re: [Tutor] variable numbers of for loops (also iteration/recursion)

2010-11-23 Thread Chris Fuller
You can always substitute Iteration for Recursion by making the stack an explicit part of your code. As an example, imagine you are traversing this directory tree: birds birds/owls birds/owls/snowy birds/owls/barn birds/owls/great-horned birds/eagles birds/eagles/golden birds/eagles/bald birds/e

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Richard D. Moores
On Tue, Nov 23, 2010 at 06:12, Steven D'Aprano wrote: > Richard D. Moores wrote: >> >> I've always disliked using "if not n % 2"  to test for even/odd ints >> because of its convoluted logic. > > I don't find it convoluted. It's not quite as straightforward as a > hypothetical "if even(n)", but it

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed:aesthetics lose

2010-11-23 Thread Emile van Sebille
On 11/23/2010 8:22 AM Alan Gauld said... "Richard D. Moores" wrote it was the way to go over "if n % 2 == 0". By my tests, it's 4.3% to 9.5% faster, depending on the integer tested - size and whether odd or even. See the speed testing script and results at

Re: [Tutor] Lambda function, was: Simple counter to determine frequencies of words in adocument

2010-11-23 Thread ALAN GAULD
> OK, all of this is perfectly clear but what is still difficult for me > to understand is the following. If you remember the line of code in > question was: > > >sorted(word_table.items(), key=lambda item: item[1], reverse=True) > > This is supposed to return a list of tuples such as > >

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed:aesthetics lose

2010-11-23 Thread ALAN GAULD
> > Did you try: > > > > if n % 2: pass > > else: do it here? > > > > ie inverting the logic and omitting the equality test. > > Alan, since I'm doing comparison's, why do you suggest omitting the > equality test? Because the equality test with 0 might be slower than the implicit test of

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed:aesthetics lose

2010-11-23 Thread Richard D. Moores
On Tue, Nov 23, 2010 at 08:22, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> it was the way to go over "if n % 2 == 0". By my tests, it's 4.3% to >> 9.5% faster, depending on the integer tested - size and whether odd or >> even. See the speed testing script and results at >>

Re: [Tutor] Tutor Digest, Vol 81, Issue 78

2010-11-23 Thread Emile van Sebille
On 11/23/2010 7:30 AM Wangolo Joel said... I NO LONGER WANT YOUR TUTORIAL you can unsubscribe at http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://

Re: [Tutor] Fw: Installing Pyserial for Python27 on Win 7

2010-11-23 Thread Emile van Sebille
On 11/23/2010 5:57 AM Walter Prins said... On 23 November 2010 03:02, John Smith wrote: I like Python itself. Very powerful. But I guess I'll look for some other language which provides the features I need without the hassle. Thanks again for your help. In any case for the record, Python sou

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed:aesthetics lose

2010-11-23 Thread Alan Gauld
"Richard D. Moores" wrote it was the way to go over "if n % 2 == 0". By my tests, it's 4.3% to 9.5% faster, depending on the integer tested - size and whether odd or even. See the speed testing script and results at . Did you try: if n % 2: pass else

Re: [Tutor] IDEs

2010-11-23 Thread Mac Ryan
On Tue, 23 Nov 2010 15:02:27 +0100 "Josep M. Fontana" wrote: > Does anybody know of any good reference on testing? How do you develop > tests for functions? I haven't found much information on this in the > Python books I own. When I first learnt python I found the "Dive into Python" section of

Re: [Tutor] IDEs

2010-11-23 Thread Eike Welk
On Tuesday 23.11.2010 15:02:27 Josep M. Fontana wrote: > Does anybody know of any good reference on testing? How do you develop > tests for functions? I haven't found much information on this in the > Python books I own. The basic idea is to call your function with known inputs, and test if it ha

Re: [Tutor] Tutor Digest, Vol 81, Issue 78

2010-11-23 Thread Wangolo Joel
 I NO LONGER WANT YOUR TUTORIAL ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Steven D'Aprano
Richard D. Moores wrote: I've always disliked using "if not n % 2" to test for even/odd ints because of its convoluted logic. I don't find it convoluted. It's not quite as straightforward as a hypothetical "if even(n)", but it's pretty straightforward. Perhaps you just need to get used it i

Re: [Tutor] IDEs

2010-11-23 Thread Josep M. Fontana
Hi Steven, > Also, I'm a big believer in test-driven development. I must admit though I'm > not so pedantic to write the tests first, but for anything except > quick-and-dirty scripts, I make sure that *every* function in my program, > without exception, has a test to ensure that it works correctl

Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Mac Ryan
On Tue, 23 Nov 2010 13:16:46 + Jose Amoreira wrote: > I read somewhere that for any recursive algorithm there is a > sequential one that is equivalent > [...] > Is there a more straightforward way of solving my specific problem > or, better yet, a general solution to the need of a variable nu

Re: [Tutor] Fw: Installing Pyserial for Python27 on Win 7

2010-11-23 Thread Walter Prins
On 23 November 2010 03:02, John Smith wrote: > I _assume_ the source is the one that is a tar.gz thingy. Since Windows > will not handle the unpacking of that, I have to install a > decompressor/unpacker to do it. Then I can finally get around to installing > the serial package. Maybe. Unless I r

Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Andre Engels
On Tue, Nov 23, 2010 at 2:16 PM, Jose Amoreira wrote: > Is there a more straightforward way of solving my specific problem or, better > yet, a general solution to the need of a variable number of for loops? If you need a variable number of loops, put the loops themselves in a loop, which you go

[Tutor] variable numbers of for loops

2010-11-23 Thread Jose Amoreira
Hi, This is a somewhat algorithmic question, not strictly pythonic. I was writing a program to generate all possible n-letter words with letters taken from an alphabet (I mean, if the alphabet is ['a','b'] the one-letter words are 'a' and 'b', the two letter words are 'aa', 'ab', 'ba', 'bb' and

Re: [Tutor] IDEs

2010-11-23 Thread Josep M. Fontana
Great. Thanks Marc, Steven and Alan for the enlightening answers. I will certainly take your advice into account. I work in many different computers and while I do most of my coding (sounds as if I did a lot of coding, but I don't) on my desktop computer at home I wanted to start doing it on my la

[Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread Richard D. Moores
I've always disliked using "if not n % 2" to test for even/odd ints because of its convoluted logic. But I ran some speed tests and found it was the way to go over "if n % 2 == 0". By my tests, it's 4.3% to 9.5% faster, depending on the integer tested - size and whether odd or even. See the speed