Import statements for timeit module

C

ChaosKCW

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,

import cx_Oracle
import timeit

def VerifyTagIntegrity(con, TableOwner):
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)
timer = timeit.Timer('cur.execute(sql)', 'from __main__ import
cur')
print timer.timeit()
 
B

bruno at modulix

ChaosKCW said:
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,

import cx_Oracle
import timeit

def VerifyTagIntegrity(con, TableOwner):
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)
timer = timeit.Timer('cur.execute(sql)', 'from __main__ import
cur')
print timer.timeit()

'cur' is local to the function, so it's not an attribute of your module,
so you can't hope to import it anyway.
 
A

Alex Martelli

ChaosKCW said:
So timeit is mostly useless then ?

No, it's a precious jewel, but if you want to use it you must allow it
to import the code you want it to run.


Alex
 
S

Scott David Daniels

bruno said:
....>
'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:
timer = timeit.Timer('cur.execute(sql)', ###
'from __main__ import cur, sql') ###
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top