[Tutor] TypeError when io.open is used

2010-06-23 Thread petkovas
Hello all! I would like to ask you the following: what should i do to be executed my correctly? The error: Traceback : File "insert_into_db_v9.py", line 55, in TypeError: an integer is required The code i use is the following: import psycopg2 import os from os import sep, listdir, path im

[Tutor] unsubscribe

2010-06-23 Thread Benjamin Pritchard
unsubscribe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Use flag to exit?

2010-06-23 Thread Eike Welk
On Thursday June 24 2010 07:31:47 Richard D. Moores wrote: > My question is how to best exit when the big prime has been found. I > used a flag (see the highlighted lines 34,40,44), but I seem to > remember that, though they can work, flags are frowned upon by > Pythonistas, and should be used only

Re: [Tutor] Repeat function until...

2010-06-23 Thread Nethirlon
On Wed, Jun 23, 2010 at 10:13 PM, Steven D'Aprano wrote: > On Thu, 24 Jun 2010 04:09:38 am Alan Gauld wrote: >> "Steven D'Aprano" wrote >> >> > The easiest way is to just run forever, and stop when the user >> > interrupts it with ctrl-D (or ctrl-Z on Windows): >> >> I think that would be Ctrl-C

[Tutor] Use flag to exit?

2010-06-23 Thread Richard D. Moores
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 has been proven or not, but I've tested it on all primes 3 < p <=

Re: [Tutor] finally

2010-06-23 Thread bob gailer
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 block without using a finally block. Does t

[Tutor] finally

2010-06-23 Thread Christopher King
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 finally block. Does the finally command do something I don't know about

Re: [Tutor] Repeat function until...

2010-06-23 Thread Steven D'Aprano
On Thu, 24 Jun 2010 04:09:38 am Alan Gauld wrote: > "Steven D'Aprano" wrote > > > The easiest way is to just run forever, and stop when the user > > interrupts it with ctrl-D (or ctrl-Z on Windows): > > I think that would be Ctrl-C on both. > Ctrl-D/Z is EOF not Interrupt. Certainly on Windows Ctr

Re: [Tutor] Repeat function until...

2010-06-23 Thread Sithembewena Lloyd Dube
My code has two bugs. If any command other than an int is entered, it falls over ungracefully. Also, if any integers other than 1 or 0 are entered successively it exits the Python interpreter. I thought I would point this out so as not to mislead the OP. On Wed, Jun 23, 2010 at 8:09 PM, Alan Gaul

Re: [Tutor] Repeat function until...

2010-06-23 Thread Alan Gauld
"Steven D'Aprano" wrote The easiest way is to just run forever, and stop when the user interrupts it with ctrl-D (or ctrl-Z on Windows): I think that would be Ctrl-C on both. Ctrl-D/Z is EOF not Interrupt. Certainly on Windows Ctrl-Z won't interrupt a loop. But the principle is good and

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

2010-06-23 Thread python
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? The following email exchange seems to support my conclusion that the ftplib module only supports ASCII file names. Should f

Re: [Tutor] split struggle

2010-06-23 Thread Peter Otten
Richard D. Moores wrote: > Please see my Python 3.1 code pasted at > . > > This does what I want, which is to do one of: > 1. print all the elements of the list, lst. > 2. print "Done" when "" is entered. > 3. print the elements of lst whose indexes are entere

Re: [Tutor] Repeat function until...

2010-06-23 Thread Dave Angel
Steven D'Aprano wrote: On Wed, 23 Jun 2010 10:29:11 pm Nethirlon . wrote: Hello everyone, I'm new at programming with python and have a question about how I can solve my problem the correct way. Please forgive my grammar, English is not my primary language. I'm looking for a way to repeat

Re: [Tutor] Repeat function until...

2010-06-23 Thread Sithembewena Lloyd Dube
^^ I meant time.sleep(x), rather. Please excuse the double post. On Wed, Jun 23, 2010 at 4:29 PM, Sithembewena Lloyd Dube wrote: > My two cents' worth added below. Seems to do what you want. You probably > want to call sys.wait(x) after printing an error, so it can be read before > exiting? > > i

Re: [Tutor] Repeat function until...

2010-06-23 Thread Sithembewena Lloyd Dube
My two cents' worth added below. Seems to do what you want. You probably want to call sys.wait(x) after printing an error, so it can be read before exiting? import os, sys, time def check(host): try: output = os.popen('ping -ns 1 %s' % host).read() alive = output.find('Reply fro

Re: [Tutor] Repeat function until...

2010-06-23 Thread Emile van Sebille
On 6/23/2010 6:51 AM Steven D'Aprano said... # untested def call_again(n, func, *args): """call func(*args) every n seconds until ctrl-D""" import time try: while 1: start = time.time() func(*args) time.sleep(n - (time.time()-start))

Re: [Tutor] Repeat function until...

2010-06-23 Thread Steven D'Aprano
On Wed, 23 Jun 2010 10:29:11 pm Nethirlon . wrote: > Hello everyone, > > I'm new at programming with python and have a question about how I > can solve my problem the correct way. Please forgive my grammar, > English is not my primary language. > > I'm looking for a way to repeat my function every

Re: [Tutor] Repeat function until...

2010-06-23 Thread Adam Bark
On 23 June 2010 13:29, Nethirlon . wrote: > Hello everyone, > > I'm new at programming with python and have a question about how I can > solve my problem the correct way. Please forgive my grammar, English > is not my primary language. > > I'm looking for a way to repeat my function every 30 seco

[Tutor] Repeat function until...

2010-06-23 Thread Nethirlon .
Hello everyone, I'm new at programming with python and have a question about how I can solve my problem the correct way. Please forgive my grammar, English is not my primary language. I'm looking for a way to repeat my function every 30 seconds. As an example I have written a ping function. But

Re: [Tutor] Time

2010-06-23 Thread Steven D'Aprano
On Wed, 23 Jun 2010 11:11:32 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. > > import time > > start = time.ti

Re: [Tutor] Calling a number's methods

2010-06-23 Thread Steven D'Aprano
On Wed, 23 Jun 2010 04:47:47 pm Alan Gauld wrote: > "Mark Young" wrote > > > I searched the internet, and found someone suggest adding spaces > > after each > > number, which indeed works properly. > > > answer = 6 .__sub__(7 .__neg__()) > answer > > > > 13 > > > > Why does this work? I

Re: [Tutor] Calling a number's methods

2010-06-23 Thread Mark Young
Hmm, apparently python doesn't care about whitespace in method calls or attribute access: class person: def __init__(self): self.name ="jim" def hi(self): print("hello") >>> guy = person() >>> guy. name 'jim' >>> guy .hi() hello That at least explains that par