[Tutor] Problem with Learning Python example

->Terry<- tvbare at socket.net
Thu Aug 11 22:10:19 CEST 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hello,

I'm working my way through Learning Python 2nd Ed. and
I've ran across something I don't understand in Chapter
27, page 482, in Timing section. I checked the errata on
O'Reilly's web-site and it only mentions a missing comma
in the print statement in timings.py, which I caught when
I first ran the program. I've proof-read these 2 files
several times and even had the wife proof-read it and I'm
fairly confident I'm not missing any errors. Can someone
guide me in the right direction?

My system is Slackware 10.1 and Python version is 2.4.1

- --------------------------------
* makezeros.py
- --------------------------------

def lots_of_appends():
     zeros = []
     for i in range(10000):
         zeros.append(0)

def one_multiply():
     zeros = [0] * 10000


- --------------------------------
* timings.py
- --------------------------------

import time, makezeros
def do_timing(num_times, *funcs):
     totals = {}
     for func in funcs:
         totals[func] = 0.0
         starttime = time.clock()        # record starting time
         for x in range(num_times):
             for func in funcs:
                 apply(func)
         stoptime = time.clock()          # record ending time
         elapsed = stoptime - starttime   # difference yields time elapsed
         totals[func] = totals[func] + elapsed
     for func in funcs:
         print "Running %s %d times took %.3f seconds" % (func.__name__, num_times, totals[func])

do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))


- -------------------------------
* error message
- -------------------------------

Traceback (most recent call last):
   File "timings.py", line 16, in ?
     do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))
   File "timings.py", line 9, in do_timing
     apply(func)
TypeError: 'tuple' object is not callable


Thanks,
- -- 
     Terry

      ,-~~-.___.     Terry Randall <tvbareATsocketDOTnet>
     / |  '     \
    <   )        0    Linux Counter Project User# 98233
     \_/, ,-----'
        ====          //
       /  \-'~;    /~~~(0)
      /  __/~|   /      |   If only Snoopy had Slackware...
    =( ______| (________|

"He is your friend, your partner, your defender, your dog.
You are his life, his love, his leader. He will be yours,
faithful and true, to the last beat of his heart. You owe
it to him to be worthy of such devotion."    -- Unknown

          (Best viewed with a mono-spaced font.)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFC+7CwQvSnsfFzkV0RAqVoAJwIodb3VcBEYlneak47zjrIJdsLagCgg0xL
lss+Go8izUgD9ekCE7B5nKE=
=fzYk
-----END PGP SIGNATURE-----



More information about the Tutor mailing list