473,588 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import statements for timeit module

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 VerifyTagIntegr ity(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('c ur.execute(sql) ', 'from __main__ import
cur')
print timer.timeit()

Nov 11 '05 #1
5 1934
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,

import cx_Oracle
import timeit

def VerifyTagIntegr ity(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('c ur.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.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Nov 11 '05 #2
So timeit is mostly useless then ?

Nov 11 '05 #3
ChaosKCW <da********@gma il.com> wrote:
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
Nov 11 '05 #4
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 VerifyTagIntegr ity(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('c ur.execute(sql) ', 'from __main__ importcur') timer = timeit.Timer('c ur.execute(sql) ', ###
'from __main__ import cur, sql') ### print timer.timeit()


--
-Scott David Daniels
sc***********@a cm.org
Nov 11 '05 #5
ChaosKCW wrote:
So timeit is mostly useless then ?

I wouldn't say so.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Nov 11 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2233
by: Matthew Wilson | last post by:
Hi- I'm writing a bunch of classes, several of which need functions and variables defined in the math module. In some instances, I'm going to import my module like this: import myshapes and then in others, I'll do:
9
2932
by: Paul Rubin | last post by:
That's what the Python style guides advise. They don't seem to like def frob(x): import re if re.search('sdfxyz', x): ... instead preferring that you pollute your module's global namespace with the names of all your imports. What's the point of that? It gets worse when you want to do something like
0
1122
by: myang | last post by:
I am revising a python module, and try it in python shell. Each time after the module is modified, how can I import the new module? I remember there is an "import" like staff to do it, but dont know its name clearly. I was not able to google out it, and the huge bulk of python documentation is fearsome. :( Regards, Yang
2
2439
by: Roy Smith | last post by:
I'm playing with the timeit module, and can't figure out how to time a function call. I tried: def foo (): x = 4 return x t = timeit.Timer ("foo()") print t.timeit()
1
4164
by: Dennis B. Hansen | last post by:
Hi all... I'm having some problems JAXB compiling som schemas, and was wondering if what i was trying to do is simply wrong... the problem seems to be with my import statements, and I've tried to create a simple example that generates the error (included below). I have two imported schemas, and JAXB seems to only want to import one of them (possibly because they have same namespace (???)).
1
1402
by: Shane Hathaway | last post by:
Let's talk about the problem I really want help with. I brought up a proposal earlier, but it was only half serious. I realize Python is too sacred to accept such a heretical change. ;-) Here's the real problem: maintaining import statements when moving sizable blocks of code between modules is hairy and error prone. I move major code sections almost every day. I'm constantly restructuring the code to make it clearer and simpler, to...
2
2688
by: Steven D'Aprano | last post by:
When using the timeit module, you pass the code you want to time as strings: import timeit t = timeit.Timer("foo(x, y)", \ """from module import foo x = 27 y = 45 """) elapsed_time = t.timeit()
9
2858
by: BartlebyScrivener | last post by:
I know this must have been answered a hundred times, but I must be searching on the wrong terminology. Let's say I have a module foo.py that imports os. I make another script called bar.py that imports foo.py and now I want to use, say, os.walk in bar.py. Which is faster or more correct or whatever: Do I import os at the top of bar.py and use foo's functions?
9
2061
by: Phoe6 | last post by:
Hi, Following are my files. In the format: Filename ---- content ---- config1.txt
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7862
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5729
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2372
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.