Re: [Tutor] TypeError when io.open is used

2010-06-24 Thread Alan Gauld
wrote The error: Traceback : File "insert_into_db_v9.py", line 55, in TypeError: an integer is required Can you send the full error text please? I'm not sure which is line 55 and Python normally displays the faulty line as part of the error trace. As it is I can't see any reason for i

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Wed, Jun 23, 2010 at 23:47, Eike Welk wrote: > On Thursday June 24 2010 07:31:47 Richard D. Moores wrote: > I hope I didn't break your algorithm; I'm typing this directly into the email > program. I did what you said (), and get "invalid syntax" for the

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Wed, Jun 23, 2010 at 22:31, Richard D. Moores wrote: > I've read (I can't remember where) that for every prime p there there > are positive integers a and b such that p = a + b and such that > 2**a*3**b is either 1 greater than or 1 less than another (much > larger) prime. I don't know if this

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Eike Welk
On Thursday June 24 2010 09:16:05 Richard D. Moores wrote: > I did what you said (), and get > "invalid syntax" for the comma in line 40. Are you using Python 3? (I'm using Python 2.6) For Python 3 the correct syntax of the except clause is: except FoundP

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 02:33, Eike Welk wrote: > On Thursday June 24 2010 09:16:05 Richard D. Moores wrote: > >> I did what you said (), and get >> "invalid syntax" for the comma in line 40. > > Are you using Python 3? (I'm using Python 2.6) For Python 3 the

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Eike Welk
On Thursday June 24 2010 12:15:25 Richard D. Moores wrote: > OK. See . What now? Ah... my bad. Line 8 must be changed to: self.big_p = big_p Eike. ___ Tutor maillist - Tutor@python.org To unsubscribe or

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 03:36, Eike Welk wrote: > On Thursday June 24 2010 12:15:25 Richard D. Moores wrote: >> OK. See . What now? > > Ah... my bad. Line 8 must be changed to: >        self.big_p = big_p Yes! Perfect! Now, Eike, if I only understand what yo

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Steven D'Aprano
On Thu, 24 Jun 2010 08:51:26 pm Richard D. Moores wrote: > How about using sys.exit() instead? sys.exit() is almost always evil. Here's the problem: One day, you find a nice library that has some function you need. Perhaps it's even a library you wrote yourself: from library import print_next

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Eike Welk
On Thursday June 24 2010 12:51:26 Richard D. Moores wrote: > On Thu, Jun 24, 2010 at 03:36, Eike Welk wrote: > > On Thursday June 24 2010 12:15:25 Richard D. Moores wrote: > >> OK. See . What now? > > > > Ah... my bad. Line 8 must be changed to: > >se

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 04:55, Eike Welk wrote: > On Thursday June 24 2010 12:51:26 Richard D. Moores wrote: >> On Thu, Jun 24, 2010 at 03:36, Eike Welk wrote: >> > On Thursday June 24 2010 12:15:25 Richard D. Moores wrote: >> Yes! Perfect! Now, Eike, if I only understand what you wrote. You >>

Re: [Tutor] Time

2010-06-24 Thread Hugo Arts
On Wed, Jun 23, 2010 at 3:11 AM, Dave Angel wrote: > > If you're really looking to measure performance, you should use the timeit > module.  But for simply deciding how much time has elapsed between two > points in your code, you can use the time.time() function. > Another one I think is worth me

Re: [Tutor] finally

2010-06-24 Thread Hugo Arts
On Thu, Jun 24, 2010 at 4:36 AM, Christopher King wrote: >     In a try except clause, you can end with finally block. I know it runs > after the try and except blocks regardless of the outcome, but why use it. > Couldn't you just put the code after the try and except block without using > a final

Re: [Tutor] finally

2010-06-24 Thread Christopher King
you mean it will always run even if the exception is handled? On Thu, Jun 24, 2010 at 9:06 AM, Hugo Arts wrote: > On Thu, Jun 24, 2010 at 4:36 AM, Christopher King > wrote: > > In a try except clause, you can end with finally block. I know it > runs > > after the try and except blocks regar

Re: [Tutor] finally

2010-06-24 Thread Christopher King
i mean isn't handled On Thu, Jun 24, 2010 at 9:12 AM, Christopher King wrote: > you mean it will always run even if the exception is handled? > > > On Thu, Jun 24, 2010 at 9:06 AM, Hugo Arts wrote: > >> On Thu, Jun 24, 2010 at 4:36 AM, Christopher King >> wrote: >> > In a try except clause,

Re: [Tutor] finally

2010-06-24 Thread Christopher King
what manual? On Wed, Jun 23, 2010 at 10:59 PM, bob gailer wrote: > On 6/23/2010 7:36 PM, Christopher King wrote: > > In a try except clause, you can end with finally block. I know it runs > after the try and except blocks regardless of the outcome, but why use it. > Couldn't you just put th

Re: [Tutor] Time

2010-06-24 Thread Christopher King
I have a module which measures elapsed time. It can also wait til a certain amount of time has passed till ending. I can send it to you if you like. On Thu, Jun 24, 2010 at 8:59 AM, Hugo Arts wrote: > On Wed, Jun 23, 2010 at 3:11 AM, Dave Angel wrote: > > > > If you're really looking to measure

Re: [Tutor] finally

2010-06-24 Thread Hugo Arts
On Thu, Jun 24, 2010 at 3:13 PM, Christopher King wrote: > i mean isn't handled > When I said "guaranteed to run," I meant it. finally will *always* run after your try clause, exceptions or not, handled or not. And by manual, he means the python reference manual. He was quoting a part covering th

[Tutor] Line wrapping in IDLE possible? Horizontal scroll bar?

2010-06-24 Thread Richard D. Moores
I use IDLE v3.1.1 occasionally on Vista. There doesn't seem to be a way to configure it to wrap long lines (they do wrap in the IDLE shell). Or is there? Also, when there's an unwrapped long line that extends past the right edge of the window frame, the only way to see the line's tail is to place

Re: [Tutor] finally

2010-06-24 Thread Christopher King
so if you encounter an error that you won't handle, but you still to close files and save data, you could use finally? On Thu, Jun 24, 2010 at 10:05 AM, Christopher King wrote: > let me try it > > On Thu, Jun 24, 2010 at 9:38 AM, Hugo Arts wrote: > >> On Thu, Jun 24, 2010 at 3:13 PM, Christopher

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 05:27, Richard D. Moores wrote: > On Thu, Jun 24, 2010 at 04:55, Eike Welk wrote: >> Looking at my solution now, I think it is too complicated for your relatively >> simple use-case. I think a better solution would be to put the nested for >> loops into a function and use

Re: [Tutor] Line wrapping in IDLE possible? Horizontal scroll bar?

2010-06-24 Thread Christopher King
well, if you use a backlash in the middle of a statement, you can continue the statement on the next line like so. >>> for \ i \ in \ ('neat', 'ha') \ : \ print \ i neat ha >>> you can abuse it as much as you like [?] On Thu, Jun 24, 2010 at 10:00 AM, Richard D. Moores wr

Re: [Tutor] Line wrapping in IDLE possible? Horizontal scroll bar?

2010-06-24 Thread Richard D. Moores
Yes, that's true, but if the line is long because of a long int? On Thu, Jun 24, 2010 at 07:18, Christopher King wrote: > > well, if you use a backlash in the middle of a statement, you can continue > the statement on the next line like so. > >>> for \ >     i \ >     in \ >     ('neat', 'ha') \

Re: [Tutor] finally

2010-06-24 Thread Walter Prins
On 24 June 2010 15:08, Christopher King wrote: > so if you encounter an error that you won't handle, but you still to close > files and save data, you could use finally? > More strongly, you *should* use finally, as there's no other way to ensure your cleanup code will run regardless of unpredic

Re: [Tutor] Line wrapping in IDLE possible? Horizontal scroll bar?

2010-06-24 Thread Chris
On 06/24/2010 10:24 AM, Richard D. Moores wrote: Yes, that's true, but if the line is long because of a long int? On Thu, Jun 24, 2010 at 07:18, Christopher King wrote: well, if you use a backlash in the middle of a statement, you can continue the statement on the next line like so.

Re: [Tutor] finally

2010-06-24 Thread Chris
On 06/24/2010 10:29 AM, Walter Prins wrote: On 24 June 2010 15:08, Christopher King @gmail.com > wrote: so if you encounter an error that you won't handle, but you still to close files and save data, you could use finally? More strongly, you *should*

Re: [Tutor] finally

2010-06-24 Thread Walter Prins
On 24 June 2010 15:34, Chris wrote: > cleanup code means code to close files and save data, right > Possibly yes, although I'm referring generally to freeing any resources (objects, memory, files, whatever) your code has acquired/opened that should be freed whether or not the code succeeds (with

Re: [Tutor] finally

2010-06-24 Thread Chris
On 06/23/2010 10:59 PM, bob gailer wrote: On 6/23/2010 7:36 PM, Christopher King wrote: In a try except clause, you can end with finally block. I know it runs after the try and except blocks regardless of the outcome, but why use it. Couldn't you just put the code after the try and except

Re: [Tutor] finally

2010-06-24 Thread Chris
On 06/24/2010 10:44 AM, Walter Prins wrote: On 24 June 2010 15:34, Chris http://g.nius.ck>@gmail.com > wrote: cleanup code means code to close files and save data, right Possibly yes, although I'm referring generally to freeing any resources (objects, memory, files, wha

Re: [Tutor] unsubscribe

2010-06-24 Thread bob gailer
On 6/23/2010 8:35 AM, Benjamin Pritchard wrote: unsubscribe You have to do that yourself. The instructions are always included in posts sent from the list: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Alan Gauld
"Richard D. Moores" wrote How can I prevent Traceback (most recent call last): File "C:/P31Working/prime_to_biggest_prime_tutor3.py", line 45, in sys.exit() SystemExit from printing? Or isn't using sys.exit() a good idea? Steven has already given you an answer to that although I'd a

[Tutor] os.startfile?

2010-06-24 Thread Jim Byrnes
I am trying to run an example program that contains the line os.startfile('socket-nongui.py') which is Windows only. What would be the command to use on Linux? All files are in the same folder. Thanks, Jim ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] os.startfile?

2010-06-24 Thread Nethirlon
On Thu, Jun 24, 2010 at 7:36 PM, Jim Byrnes wrote: > I am trying to run an example program that contains the line > os.startfile('socket-nongui.py') which is Windows only.  What would be the > command to use on Linux?  All files are in the same folder. > > Thanks,  Jim > __

Re: [Tutor] Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

2010-06-24 Thread Lie Ryan
On 06/24/10 02:10, pyt...@bdurham.com wrote: > Can someone confirm that Python 2.6 ftplib does *NOT* support > Unicode file names? Or must Unicode file names be specially > encoded in order to be used with the ftplib module? > I don't know the specifics about ftplib, however I believe in most fil

Re: [Tutor] os.startfile?

2010-06-24 Thread Jim Byrnes
Nethirlon wrote: On Thu, Jun 24, 2010 at 7:36 PM, Jim Byrnes wrote: I am trying to run an example program that contains the line os.startfile('socket-nongui.py') which is Windows only. What would be the command to use on Linux? All files are in the same folder. Thanks, Jim _

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 10:13, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> How can I prevent >> >> Traceback (most recent call last): >>  File "C:/P31Working/prime_to_biggest_prime_tutor3.py", line 45, in >> >>   sys.exit() >> SystemExit >> >> from printing? Or isn't using sys.exit() a

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Alan Gauld
"Richard D. Moores" wrote I think I much prefer accomplishing an exit by a function return, as I do in , but if I wanted to use sys.exit() in a script (but not in a function) I run inside IDLE or Wing, how do I suppress the message? I'd just like to get

Re: [Tutor] os.startfile?

2010-06-24 Thread Alan Gauld
"Jim Byrnes" wrote The os.startfile('socket-nongui.py) line was in a gui program that demonstrates how to start and communicate with a non-gui program. It is Windows specific so I looked for but could not find a drop in replacement that works on Linux. Look at the subprocess module. That

Re: [Tutor] finally

2010-06-24 Thread Steven D'Aprano
On Thu, 24 Jun 2010 11:06:24 pm Hugo Arts wrote: > If you need to do some cleanup, putting it in a finally block is the > only way to *guarantee* it will run. To be pedantic, the finally clause will always run, *provided* the code in the try block itself exits (either by finishing or by raising

Re: [Tutor] finally

2010-06-24 Thread Steven D'Aprano
On Fri, 25 Jun 2010 12:29:12 am Walter Prins wrote: > On 24 June 2010 15:08, Christopher King wrote: > > so if you encounter an error that you won't handle, but you still > > to close files and save data, you could use finally? > > More strongly, you *should* use finally, as there's no other way t

Re: [Tutor] Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

2010-06-24 Thread Steven D'Aprano
On Fri, 25 Jun 2010 04:51:13 am Lie Ryan wrote: > On 06/24/10 02:10, pyt...@bdurham.com wrote: > > Can someone confirm that Python 2.6 ftplib does *NOT* support > > Unicode file names? Or must Unicode file names be specially > > encoded in order to be used with the ftplib module? > > I don't know t

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 17:06, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> I think I much prefer accomplishing an exit by a function return, as I >> do in , but if I wanted to use >> sys.exit() in a script (but not in a function) I run inside IDLE o

Re: [Tutor] Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

2010-06-24 Thread Sander Sweers
- Original message - > On Fri, 25 Jun 2010 04:51:13 am Lie Ryan wrote: > > On 06/24/10 02:10, pyt...@bdurham.com wrote: > > > Can someone confirm that Python 2.6 ftplib does *NOT* support > > > Unicode file names? Or must Unicode file names be specially > > > encoded in order to be used wit