Re: [Tutor] time taken to execute certain task

2011-03-16 Thread Modulok
On 3/16/11, tee chwee liong 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() > #pr

Re: [Tutor] time taken to execute certain task

2011-03-16 Thread Jack Trades
On Wed, Mar 16, 2011 at 9:40 PM, tee chwee liong 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=

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

2011-03-16 Thread Bill Allen
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? I have found lots of recipes out there to do these, but have not yet found a canned l

[Tutor] time taken to execute certain task

2011-03-16 Thread tee chwee liong
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() #print start for n in range(num): #print

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

2011-03-16 Thread Alan Gauld
"Shane O'Connor" wrote 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 It is impossible to tell and 99% of the time irrelevant si

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

2011-03-16 Thread Corey Richardson
On 03/16/2011 08:32 PM, 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

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

2011-03-16 Thread Wayne Werner
On Wed, Mar 16, 2011 at 7:32 PM, 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 >

[Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Shane O'Connor
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 In my mind, the while loop should

Re: [Tutor] Boolean question

2011-03-16 Thread Alan Gauld
"Donald Bedsole" wrote False or thing = thing Thanks for your response and for the rules, but for some reason I'm not understanding. In the above quote, what is meant by "thing"? Any Boolean value, and in Python that means pretty much anything at all because Python has a set of rules ove

Re: [Tutor] Boolean question

2011-03-16 Thread Alan Gauld
"Donald Bedsole" wrote The first argument was "True", so "True" was returned and negated by the "not" with a final result of "False" for the expression. Is this correct? Yes. Its called Short Circuit Evaluation. You will find an explanation on the Functional Programming topic of my tutor HT

Re: [Tutor] Boolean question

2011-03-16 Thread Donald Bedsole
Hi Jack, On Wed, Mar 16, 2011 at 1:55 AM, Jack Trades wrote: 'and' evaluates one argument at a time and returns immediately if the argument is False. > And "or" works in the inverse manner? It "evaluates one argument at a time and returns immediately if the argument is [True]." ? For examp

Re: [Tutor] Boolean question

2011-03-16 Thread Donald Bedsole
On Wed, Mar 16, 2011 at 5:53 PM, bob gailer wrote: > > Thing in this context means 'anything". could be a string, number, list, any > Python object. > Ok, thanks Bob. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options

Re: [Tutor] Boolean question

2011-03-16 Thread bob gailer
On 3/16/2011 4:26 PM, Donald Bedsole wrote: Hi Allen, Boolean algebra can be a weird thing to get your head around the first time you come across it :-) Yes, :-) Here are some of the standard rules: True and thing = thing False and thing = False True or thing = True False or thing = thing

Re: [Tutor] Boolean question

2011-03-16 Thread Donald Bedsole
Hi Allen, > Boolean algebra can be a weird thing to get your head around > the first time you come across it :-) Yes, :-) > Here are some of the standard rules: > > True and thing = thing > False and thing = False > True or thing = True > False or thing = thing > Thanks for your response and fo

[Tutor] ctypes and spssio.dll

2011-03-16 Thread Albert-Jan Roskam
Hi, I'm still working on a program that uses a .dll to read SPSS system files. It's getting somewhere already, but I'm still struggling with one thing. When using the C function spssGetVarNames I'm having trouble translating C arrays to Python lists. I want to translate an array that holds the

[Tutor] Check my dummy application

2011-03-16 Thread Yaşar Arabacı
hi, While I was trying to learn python by doing it. I created a really primitive app, called best buy. You can find it here: http://ug.bcc.bilkent.edu.tr/~y_arabaci/best_buy.tar.gz Here is what this code suppossed to do: *You add products with its name, price and rating: Note : Rating defin

Re: [Tutor] CSV to Excel

2011-03-16 Thread Susana Iraiis Delgado Rodriguez
Thank you for your help! Once I read your comments I tried both corrections in my code, but none of them we're sucessful. Tim's idea kept the quotes at the moment I open the csv in Excel, quotues appeared at the beggining and the end of the row for Excel. Joel's idea wrote just tha variable name '

Re: [Tutor] atr in dir Vs. hasattr

2011-03-16 Thread Tim Johnson
* Steven D'Aprano [110316 05:26]: > Tim Johnson wrote: > > What is the difference between using > > hasattr(object, name) > > and > > name in dir(object) > > ? > > Did you read the Fine Manual? No but I will :) > http://docs.python.org/library/functions.html#dir > > "The default dir() mechanis

Re: [Tutor] Processing Financial Calculations using Python

2011-03-16 Thread James Reynolds
For all of these, I wrote my own class with methods to create the correct output. there is not built in python functionality that I know, although there may be a package. For IRR, the method expects a list and at least one negative value. I believe the way I did NPV was a dictionary, where the key

Re: [Tutor] atr in dir Vs. hasattr

2011-03-16 Thread Steven D'Aprano
Tom Zych wrote: I suppose there must be some reliable way to get a list of *all* an object's attributes, but I don't see it. Nope, there isn't, because Python allows classes to define arbitrary attributes at runtime. >>> import random >>> class Funny: ... def __getattr__(self, name): .

Re: [Tutor] how to compress a folder in python

2011-03-16 Thread Corey Richardson
On 03/16/2011 09:15 AM, bhavanasi sarath wrote: i want to learn how to compress a folder which is having some text filesbut compress that from another directory.. http://docs.python.org/library/zipfile.html (Sorry for the HTML email, getting things set up on new workstation) _

Re: [Tutor] how to compress a folder in python

2011-03-16 Thread Steven D'Aprano
bhavanasi sarath wrote: i want to learn how to compress a folder which is having some text filesbut compress that from another directory.. http://docs.python.org/library/archiving.html Let us know if this doesn't help. -- Steven ___ Tutor mail

Re: [Tutor] atr in dir Vs. hasattr

2011-03-16 Thread Tom Zych
On Thu, 17 Mar 2011 00:12 +1100, "Steven D'Aprano" wrote: > And here's an example: > > >>> class C(object): > ... pass > ... > >>> hasattr(C, '__eq__') > True > >>> '__eq__' in dir(C) > False OTOH, I got True in 3.1.1. As the docs say, detailed behavior may change across releases. I supp

Re: [Tutor] atr in dir Vs. hasattr

2011-03-16 Thread Steven D'Aprano
Wayne Werner wrote: However, rare is the occasion that you should use either of these. If you're doing something like: if hasattr(myobj, 'something'): myobj.something() else: print "blah blah blah" then what you really should be doing is: try: myobj.something() except AttributeErro

[Tutor] how to compress a folder in python

2011-03-16 Thread bhavanasi sarath
i want to learn how to compress a folder which is having some text filesbut compress that from another directory.. -- $$$ Bhavanasi $$$ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org

Re: [Tutor] atr in dir Vs. hasattr

2011-03-16 Thread Steven D'Aprano
Tim Johnson wrote: What is the difference between using hasattr(object, name) and name in dir(object) ? Did you read the Fine Manual? http://docs.python.org/library/functions.html#dir "The default dir() mechanism behaves differently with different types of objects, as it attempts to pro

Re: [Tutor] Boolean question

2011-03-16 Thread Alan Gauld
"Donald Bedsole" wrote most part. But, could someone make sure I'm understanding this one expression correctly? not (False and True) Python evaluates it as "True" Is it because: 1)You evaluate what's in the parentheses first. A thing can not be false and true at the same time, so the answ

Re: [Tutor] first steps

2011-03-16 Thread Alan Gauld
"Ryan McAdam" wrote I saved this module to my desktop You probably need to create a Folder for your Python code or you will soon have a very busy desktop! :-) # File: chaos.py # A simple program illustrating chaotic behavior. def main(): print("This program illustrates a chaotic func