Import statements for timeit module

Scott David Daniels scott.daniels at acm.org
Fri Nov 11 11:51:40 EST 2005


bruno at modulix wrote:
> ChaosKCW wrote:
> 
>>Hi
>>
>>I was wondering if someone could help with the import statements needed
>>to use the timeit module in the following code. I need to access the
>>"cur" object.
>>
>>Thanks,
>>
...>
> 'cur' is local to the function, so it's not an attribute of your module,
> so you can't hope to import it anyway.

Although you could change your code as follows:

 >>import cx_Oracle
 >>import timeit
 >>
 >>def VerifyTagIntegrity(con, TableOwner):
       global cur, sql  ###
 >>    cur = con.cursor()
 >>    sql = 'select (select count(*) from %s.f4111) as F4111_COUNT,
 >>(select count(*) from %s.f4111_tag) as TAG_COUNT from dual;' %
 >>(TableOwner, TableOwner)
 >>    print "      SQL: %s" % (sql)
XXX>>  timer = timeit.Timer('cur.execute(sql)', 'from __main__ import
 >>cur')
       timer = timeit.Timer('cur.execute(sql)',   ###
                            'from __main__ import cur, sql') ###
 >>    print timer.timeit()

-- 
-Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list