Re: [Tutor] time taken to execute certain task

2011-03-17 Thread Modulok
On 3/16/11, tee chwee liong tc...@hotmail.com wrote: hi, i would like to know the time taken to execute a certain task in python. i used time.time and time.clock and i see the time taken is different? what is the right method to use? import time def testtime(num): start=time.time()

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Stefan Behnel
Shane O'Connor, 17.03.2011 01:32: In particular, I'm using Python 2.4.3 on a web server which needs to run as fast as possible using as little memory as possible (no surprises there!). Note that a web application involves many things outside of your own code that seriously impact the

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Andre Engels
On Thu, Mar 17, 2011 at 8:45 AM, Stefan Behnel stefan...@behnel.de wrote: Note that a web application involves many things outside of your own code that seriously impact the performance and/or resource requirements. Database access can be slow, excessively dynamic page generation and template

Re: [Tutor] time taken to execute certain task

2011-03-17 Thread Alan Gauld
tee chwee liong tc...@hotmail.com wrote i would like to know the time taken to execute a certain task in python. i used time.time and time.clock and i see the time taken is different? what is the right method to use? Neither of those, either use timeit() or the Python profiler. They are

Re: [Tutor] Linux library for getch() and kbhit()?

2011-03-17 Thread Alan Gauld
Bill Allen walle...@gmail.com wrote I have found that for the Windows build of Python the msvcrt library provides getch() and kbhit() functions. Is there a library available for the Linux Python build that provides the same or similar functions? curses. Take a look at the event handling

Re: [Tutor] time taken to execute certain task

2011-03-17 Thread tee chwee liong
hi, i used profiler. but it gives 0 sec? is this expected? tq profile.run('import math') 3 function calls in 0.000 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 10.0000.0000.0000.000

Re: [Tutor] CSV to Excel

2011-03-17 Thread Tim Golden
On 16/03/2011 17:12, Susana Iraiis Delgado Rodriguez wrote: Thank you for your help! Once I read your comments I tried both corrections in my code, but none of them we're sucessful. Ok, Susana, your problem (here) is the use of the csv module so can I suggest we back away from your wider

Re: [Tutor] time taken to execute certain task

2011-03-17 Thread ALAN GAULD
Profiling is really intended to profile a complex set of operations not a single statement, for that timeit() would be a better choice. However in this case, it may be that the time is so low it simply doesn't register. Have you already imported math for example? In which case you are

[Tutor] CSV Ouptut concern...

2011-03-17 Thread Dipo Elegbede
i wrote a code for extracting information from a csv file into another csv file. it worked well but i have an immediate challenge i can't seem to fix. the new file that is created has an row and then an empty row and then a row all through the file. how can i make the empty rows not be part of the

Re: [Tutor] CSV Ouptut concern...

2011-03-17 Thread Tim Golden
On 17/03/2011 11:56, Dipo Elegbede wrote: i wrote a code for extracting information from a csv file into another csv file. it worked well but i have an immediate challenge i can't seem to fix. the new file that is created has an row and then an empty row and then a row all through the file. how

Re: [Tutor] CSV Ouptut concern...

2011-03-17 Thread Dipo Elegbede
Thanks Tim, that worked like magic. I now have another challenge on the same file, in this case, i am trying to extract just a column as PARTY, I successfully wrote the header but instead of having each element in a single excel block like this: A ACD ACN ACPN AD ADC ALP ANPP APGA APS ARP BNPP

Re: [Tutor] CSV Ouptut concern...

2011-03-17 Thread Joel Goldstick
On Thu, Mar 17, 2011 at 8:53 AM, Dipo Elegbede delegb...@dudupay.comwrote: Thanks Tim, that worked like magic. I now have another challenge on the same file, in this case, i am trying to extract just a column as PARTY, I successfully wrote the header but instead of having each element in a

Re: [Tutor] CSV Ouptut concern...

2011-03-17 Thread Dipo Elegbede
The counter is there so that it limits the iteration to only the first rows, i actually left it there because i used it earlier to print out specific rows. On Thu, Mar 17, 2011 at 2:04 PM, Joel Goldstick joel.goldst...@gmail.comwrote: On Thu, Mar 17, 2011 at 8:53 AM, Dipo Elegbede

Re: [Tutor] Linux library for getch() and kbhit()?

2011-03-17 Thread Bill Allen
Alan, Ah ha, ungetch(), that is what I was needing. I had be trying to simulate kbhit() with getch() and keep being left with unhandled data in the buffer. I had resorted to a trash=raw_input() to clear it. Many thanks, Bill On Thu, Mar 17, 2011 at 04:01, Alan Gauld

[Tutor] Print/Loop Question

2011-03-17 Thread Jeff Goodwin
I'm trying to run the below program and get it to print out feedback as the loop goes. However, if you enter a number too high or too low, it skips the print statement under the if and elif clauses and asks the user to Guess a number between 1-100 again. Any suggestions on how to get it to print

Re: [Tutor] Print/Loop Question

2011-03-17 Thread michael scott
Hi Jeff how are you today? Well about your question... I copy and pasted your code and it worked fine for me. Well except for in the code bit you posted you forgot to give a guess a value before it was referred to. So under number = 44 I just wrote guess = 0 and it worked fine. But perhaps

Re: [Tutor] Print/Loop Question

2011-03-17 Thread Jack Trades
On Thu, Mar 17, 2011 at 1:19 PM, Jeff Goodwin jeffbgood...@gmail.comwrote: I'm trying to run the below program and get it to print out feedback as the loop goes. However, if you enter a number too high or too low, it skips the print statement under the if and elif clauses and asks the user to

Re: [Tutor] Print/Loop Question

2011-03-17 Thread bob gailer
On 3/17/2011 1:19 PM, Jeff Goodwin wrote: I'm trying to run the below program and get it to print out feedback as the loop goes. However, if you enter a number too high or too low, it skips the print statement under the if and elif clauses and asks the user to Guess a number between 1-100

[Tutor] Waiting until a thread ends

2011-03-17 Thread lists
Hi tutors! I'm not a hard-core programmer but have used Python in systems administration (it makes sense to me to use a scripting language which supports both Windows and Unix). The code below is an excerpt from a module I have written to collect information about hosts on my network and

Re: [Tutor] Waiting until a thread ends

2011-03-17 Thread lists
Only really glanced at this, but you seem to be checking only the last thread *after* the loop? Surely you should be storing all the threads in a list (or someplace) as you create them, and then check them all for liveness and if so join them each in turn, to ensure you only print 'FINISHED'

Re: [Tutor] Waiting until a thread ends

2011-03-17 Thread lists
Only really glanced at this, but you seem to be checking only the last thread *after* the loop? Surely you should be storing all the threads in a list (or someplace) as you create them, and then check them all for liveness and if so join them each in turn, to ensure you only print 'FINISHED'

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Steven D'Aprano
Shane O'Connor wrote: Hi, First-time poster here. I've a question about loop efficiency - I was wondering whether this code: i = 0 while i 1000: do something i+=1 is more efficient than: for i in range(1000): do something or: for i in xrange(1000): do something You can