473,418 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

mxODBC sql MSAccess

Hello, I'm new to python and trying to get records from an MSAccess
database using mxODBC. It works, but the output is not formatted the
way I want it.

Here's the script:

import mx.ODBC.Windows as odbc

driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:/Access
Databases/Quotations2005'

conn = odbc.DriverConnect(driv)
c = conn.cursor()
c.execute ("SELECT Author, Topic1, Topic2, Quote FROM QuotesToTxt WHERE
Author LIKE 'Mencken%'")

rows = c.fetchall()
for r in rows:
print r

And here's what I get:

('Mencken, H.L.', 'Americans', 'Democracy', 'Democracy is the theory
that the common people know what they want, and deserve to get it good
and hard.')
('Mencken, H.L.', 'Conscience', 'Mother-In-Law', 'Conscience is a
mother-in-law whose visit never ends. The inner voice which warns us
that someone may be looking.')

Where are the parenthese and single quotes coming from? SQL or mxODBC?
And how can I get just simple tab-delimited records with a standard
carriage return separating the records?

Thanks so much for any help.

bs

Nov 22 '05 #1
4 1433

BartlebyScrivener wrote:
Hello, I'm new to python and trying to get records from an MSAccess
database using mxODBC. It works, but the output is not formatted the
way I want it.

Here's the script:

import mx.ODBC.Windows as odbc

driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:/Access
Databases/Quotations2005'

conn = odbc.DriverConnect(driv)
c = conn.cursor()
c.execute ("SELECT Author, Topic1, Topic2, Quote FROM QuotesToTxt WHERE
Author LIKE 'Mencken%'")

rows = c.fetchall()
for r in rows:
print r

And here's what I get:

('Mencken, H.L.', 'Americans', 'Democracy', 'Democracy is the theory
that the common people know what they want, and deserve to get it good
and hard.')
('Mencken, H.L.', 'Conscience', 'Mother-In-Law', 'Conscience is a
mother-in-law whose visit never ends. The inner voice which warns us
that someone may be looking.')

Where are the parenthese and single quotes coming from? SQL or mxODBC? From Python. You data is stored as a list of tuples. And how can I get just simple tab-delimited records with a standard
carriage return separating the records?
for r in rows:
print "%s\t%s\t%s\t%s" % r

Thanks so much for any help.

bs


Nov 22 '05 #2
mxODBC implements the Python DB-API spec, which states that each "row"
of query results is returned as a tuple. If you want the data
displayed differently, you can do it yourself.

for row in rows:
print "\t".join(row)

should do it.

Nov 22 '05 #3
Works!!

Thank you all so much. I didn't know it was coming back as a tuple, and
I'm sure that would have taken me four hours to figure out.

Appreciate it!

bs

--------

Chris Curvey wrote:
mxODBC implements the Python DB-API spec, which states that each "row"
of query results is returned as a tuple. If you want the data
displayed differently, you can do it yourself.

for row in rows:
print "\t".join(row)

should do it.


Nov 22 '05 #4
BartlebyScrivener wrote:
Hello, I'm new to python and trying to get records from an MSAccess
database using mxODBC. It works, but the output is not formatted the
way I want it.

Here's the script:

import mx.ODBC.Windows as odbc

driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:/Access
Databases/Quotations2005'

conn = odbc.DriverConnect(driv)
c = conn.cursor()
c.execute ("SELECT Author, Topic1, Topic2, Quote FROM QuotesToTxt WHERE
Author LIKE 'Mencken%'")

rows = c.fetchall()
for r in rows:
print r

And here's what I get:

('Mencken, H.L.', 'Americans', 'Democracy', 'Democracy is the theory
that the common people know what they want, and deserve to get it good
and hard.')
('Mencken, H.L.', 'Conscience', 'Mother-In-Law', 'Conscience is a
mother-in-law whose visit never ends. The inner voice which warns us
that someone may be looking.')

Where are the parenthese and single quotes coming from? SQL or mxODBC?
And how can I get just simple tab-delimited records with a standard
carriage return separating the records?

Thanks so much for any help.

bs

Well you know that answer now. You might also consider using the recipe at

http://aspn.activestate.com/ASPN/Coo...n/Recipe/81189

to give you the column titles and so on.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Nov 23 '05 #5

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

Similar topics

1
by: Sean Davis | last post by:
I have just installed mxODBC on my x86_64 suse linux machine, where I use unixODBC for connection. Running queries from isql or DataManager works fine for the DSN that I am using. However, under...
3
by: Greg Corradini | last post by:
Hello, I'm trying to perform a simple insert statement into a table called Parcel_Test (see code below). Yet, I get an error message that I've never seen before (see traceback below). I've tried...
0
bartonc
by: bartonc | last post by:
This is a work in progress (current and active). There are some issues to resolve in supporting multiple connection types and I plan to add PySQLite to the mix. The this update is due to my...
0
by: eGenix Team: M.-A. Lemburg | last post by:
On 2008-10-15 20:30, Terry Reedy wrote: It's going to look even better when we release version 4.0 in a year or so ;-) FWIW, we're still waiting for the dust to settle before going for a Py3k...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.