Re: [Tutor] Making a Primary Number List generator

2013-05-16 Thread eryksun
On Thu, May 16, 2013 at 1:42 AM, eryksun wrote: > On the other hand a BufferedWriter will buffer the remaining 3000 > bytes that can't be written. You won't find out until an exception is > raised when the file is closed: Actually it was buffering all 4000 bytes. I forgot about the fast path that

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread eryksun
On Wed, May 15, 2013 at 8:07 PM, Steven D'Aprano wrote: > On 16/05/13 06:02, Alan Gauld wrote: >> >> And C's printf() returns the number of chars printed. >> I actually wish python had followed suit because, as Marc says, >> it can occasionally be useful... > > Guido's time machine strikes again.

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 5:07 PM, Steven D'Aprano wrote: > Guido's time machine strikes again. > > > py> import sys > py> sys.stdout.write('NOBODY expects the Spanish Inquisition!\n') > NOBODY expects the Spanish Inquisition! > 40 > > > The write() method of file objects in Python 3 return the num

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Steven D'Aprano
On 16/05/13 06:02, Alan Gauld wrote: On 15/05/13 16:51, Marc Tompkins wrote: Actually, I was mixing up my memory of an overloaded print() function And C's printf() returns the number of chars printed. I actually wish python had followed suit because, as Marc says, it can occasionally be usefu

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Alan Gauld
On 16/05/13 00:18, Marc Tompkins wrote: On Wed, May 15, 2013 at 3:52 PM, Marc Tompkins mailto:marc.tompk...@gmail.com>> wrote: I was thinking along the lines of an optional parameter ("verbose" or something similar), so print() would supply a return value if you asked it to but keep

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 4:14 PM, Oscar Benjamin wrote: > I don't really understand what the reason for having the information > is. Would it return the number of characters written or the number of > bytes? > It's absolutely useless in an interactive session, or any time that print() is printing

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 3:52 PM, Marc Tompkins wrote: > I was thinking along the lines of an optional parameter ("verbose" or > something similar), so print() would supply a return value if you asked it > to but keep stumm if you didn't. > After I hit Send, I thought of the obvious problem... y

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Oscar Benjamin
On 15 May 2013 23:52, Marc Tompkins wrote: > On Wed, May 15, 2013 at 3:43 PM, Oscar Benjamin > wrote: >> >> On 15 May 2013 22:21, Marc Tompkins wrote: >> > On Wed, May 15, 2013 at 1:02 PM, Alan Gauld >> > wrote: >> >> >> >> And C's printf() returns the number of chars printed. >> >> I actually

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 3:43 PM, Oscar Benjamin wrote: > On 15 May 2013 22:21, Marc Tompkins wrote: > > On Wed, May 15, 2013 at 1:02 PM, Alan Gauld > > wrote: > >> > >> And C's printf() returns the number of chars printed. > >> I actually wish python had followed suit because, as Marc says, > >>

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Oscar Benjamin
On 15 May 2013 22:21, Marc Tompkins wrote: > On Wed, May 15, 2013 at 1:02 PM, Alan Gauld > wrote: >> >> And C's printf() returns the number of chars printed. >> I actually wish python had followed suit because, as Marc says, >> it can occasionally be useful... >> > > I wonder if this would be a g

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 1:02 PM, Alan Gauld wrote: > On 15/05/13 16:51, Marc Tompkins wrote: > > Actually, I was mixing up my memory of an overloaded print() function >> > > And C's printf() returns the number of chars printed. > I actually wish python had followed suit because, as Marc says, > i

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Alan Gauld
On 15/05/13 16:51, Marc Tompkins wrote: Actually, I was mixing up my memory of an overloaded print() function And C's printf() returns the number of chars printed. I actually wish python had followed suit because, as Marc says, it can occasionally be useful... -- Alan G Author of the Learn to

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 2:26 AM, Steven D'Aprano wrote: I assumed Marc was talking hypothetically. A print function *could* > return a result, even if Python's print function does not. > > Actually, I was mixing up my memory of an overloaded print() function with Python's built-in print(). I _hav

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Steven D'Aprano
On Wed, May 15, 2013 at 10:03:20AM +0100, Oscar Benjamin wrote: > On 14 May 2013 17:11, Marc Tompkins wrote: > > Again, the return value of print() - e.g. success/failure - is > > separate from what print() actually prints. > > > I was surprised by this so I've just tested it and checked the d

Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Oscar Benjamin
On 14 May 2013 17:11, Marc Tompkins wrote: > > The OP expressed some confusion between what a function DOES and what it > RETURNS. It occurs to me that the print() function (or, more generically, > ANY print() function - it doesn't have to be Python 3) is a good > demonstration. > > Our first

Re: [Tutor] Making a Primary Number List generator

2013-05-14 Thread Marc Tompkins
On Tue, May 14, 2013 at 1:51 AM, Alan Gauld wrote: > On 14/05/13 00:01, Daniel Magruder wrote: > > I am still confused as what return does. >> > > This isn't a direct response to Alan, but to something the OP expressed many, many messages ago... The OP expressed some confusion between what a fun

Re: [Tutor] Making a Primary Number List generator

2013-05-14 Thread Alan Gauld
On 14/05/13 00:01, Daniel Magruder wrote: I am still confused as what return does. Having seen the other replies I'll try a slightly different explanation. All programs are formed by a hierarchy of functions. You start with a top level driver block which then utilizes or calls helper functio

Re: [Tutor] Making a Primary Number List generator

2013-05-14 Thread Alan Gauld
On 14/05/13 02:37, Dave Angel wrote: def counting_primes(): primelist = [] for prime in range(2,1000): if isprime(prime): primelist.append(prime) return primelist Actually no, since the OP's looking for the first 1000 primes not for all the primes under 1000. Ah

Re: [Tutor] Making a Primary Number List generator

2013-05-13 Thread Dave Angel
(Please don't top-post. And don't reply privately, as I'm not the only one reading this thread. Post the reply to the list, as you did last time with your reply-all) On 05/13/2013 09:45 PM, Daniel Magruder wrote: Dear Dave, I don't have a clue what you're confused about. Do you not unders

Re: [Tutor] Making a Primary Number List generator

2013-05-13 Thread Dave Angel
On 05/13/2013 07:55 PM, Alan Gauld wrote: On 14/05/13 00:01, Daniel Magruder wrote: That seems OK but it would be simpler with a for loop: def counting_primes(): primelist = [] for prime in range(2,1000): if isprime(prime): primelist.append(prime) return pr

Re: [Tutor] Making a Primary Number List generator

2013-05-13 Thread Dave Angel
On 05/13/2013 07:01 PM, Daniel Magruder wrote: Dear Dave, I am using python 2. I am still confused as what return does. What does it mean if a > function returns True to the caller? What is the caller? Have you ever used (called) a function? If so, you've written a caller. For example, if

Re: [Tutor] Making a Primary Number List generator

2013-05-13 Thread Marc Tompkins
On Mon, May 13, 2013 at 5:13 PM, Marc Tompkins wrote: > In fact, you could shorten your isodd() function to: > > def isodd(candidate): > >return candidate%2 !=0: > and it would function identically. > Sorry - that should be > def isodd(candidate): >return candidate%2 !=0 _

Re: [Tutor] Making a Primary Number List generator

2013-05-13 Thread Marc Tompkins
On Mon, May 13, 2013 at 4:01 PM, Daniel Magruder wrote: > Dear Dave, > I am using python 2. > I am still confused as what return does. What does it mean if a function > returns True to the caller? What is the caller? > You've defined a function - isodd - but it doesn't automatically execute. It

Re: [Tutor] Making a Primary Number List generator

2013-05-13 Thread Alan Gauld
On 14/05/13 00:01, Daniel Magruder wrote: I am still confused as what return does. > What does it mean if a function returns True to the caller? > What is the caller? The caller is the program code that calls the function. For example if I write a function def square(x): return x*x and w

Re: [Tutor] Making a Primary Number List generator

2013-05-13 Thread Daniel Magruder
Dear Dave, I am using python 2. I am still confused as what return does. What does it mean if a function returns True to the caller? What is the caller? Your code worked for returning a list of 1000 items of odd numbers, so I then tried writing a code to replay isodd to give True or False for is

Re: [Tutor] Making a Primary Number List generator

2013-05-12 Thread Amit Saha
On Sun, May 12, 2013 at 9:43 PM, Dave Angel wrote: > On 05/11/2013 09:58 PM, Daniel Magruder wrote: > > Please respond to the list, not the individual. Otherwise you're robbing > yourself and others of the possibility of learning from and helping multiple > people. I don't mind if you ALSO reply

Re: [Tutor] Making a Primary Number List generator

2013-05-12 Thread boB Stepp
On Sun, May 12, 2013 at 6:43 AM, Dave Angel wrote: [...] > With no experience in programming other languages, you'd need a different > kind of tutorial than I sought when I was learning Python. And you > absolutely need to match your tutorial against the version of Python you're > running on your

Re: [Tutor] Making a Primary Number List generator

2013-05-12 Thread Alan Gauld
On 12/05/13 12:43, Dave Angel wrote: Despite going to many sources I can not seem to find a single source that adequately explains Python 100% without any technical jargon or assumptions of prior knowledge. Its impossible to learn to program without learning technical jargon, but there are tu

Re: [Tutor] Making a Primary Number List generator

2013-05-12 Thread Dave Angel
On 05/11/2013 09:58 PM, Daniel Magruder wrote: Please respond to the list, not the individual. Otherwise you're robbing yourself and others of the possibility of learning from and helping multiple people. I don't mind if you ALSO reply to me (which is what reply-all does by default), but man

Re: [Tutor] Making a Primary Number List generator

2013-05-11 Thread Dave Angel
On 05/11/2013 04:44 PM, Daniel Magruder wrote: Dear Tutor at Python.org, I am new to the python language and have been teaching myself through various online resources. I found an exercise where I am to create a program that prints a list of the first 1000 prime numbers. After many attempts and

[Tutor] Making a Primary Number List generator

2013-05-11 Thread Daniel Magruder
Dear Tutor at Python.org, I am new to the python language and have been teaching myself through various online resources. I found an exercise where I am to create a program that prints a list of the first 1000 prime numbers. After many attempts and looking at other answers for other ways around