Best python module for Oracle, but portable to other RDBMSes
dananrg at yahoo.com
dananrg at yahoo.com
Thu Mar 2 16:45:35 EST 2006
> If you actually get a suffixed L in the resulting text file, you
> are using a strange way to convert your data to text. You aren't
> simply printing lists or tuples are you? Then other types, such as
> datetime objects will also look bizarre. (Not that the ancient
> odbc would support that...)
> You might want to look at the csv module for text export.
Thanks Magnus. I didn't know there was a csv module.
Here's how I'm getting the suffixed "L"
import dbi, odbc # Import ODBC modules
connectString = 'odbc_con_name/username/password'
dbc = odbc.odbc(connectString) # Connect to Oracle
cursor = dbc.cursor() # Create cursor
sql = "select statement here..." # Define SQL statement
cursor.execute(sql) # Execute sql statement
allRecords = cursor.fetchall() # Fetch all returned records
into a list of tuples
numRecords = len(allRecords) # Get num of records returned by
the query
# Note: I'm leaving out the for loop for this example...
# Print first record:
print allRecords[0]
>>> (872L, 'ACTIVE', <DbiDate object at 010B0B78>, <DbiDate object at 010C2ED0>, None, '1.0.0.0', None, None, None)
# Convert first tuple to a list so I have a mutable object
recordList = list(allRecords[0])
# Print new list
print recordList
>>> [872L, 'ACTIVE', <DbiDate object at 011F6000>, <DbiDate object at 00EA1428>, None, '1.0.0.0', None, None, None]
# Convert long integer to short integer (int) to get rid of the "L"
recordList[0] = int(recordList[0])
# Print list with changed item. No more "L"
print recordList[0]
>>> [872, 'ACTIVE', <DbiDate object at 011F6000>, <DbiDate object at 00EA1428>, None, '1.0.0.0', None, None, None]
# The End
Are you saying I'm getting the "L" as an artifact of printing?
More information about the Python-list
mailing list