Database Programming

Arnaldo Riquelme javanet at dynacap.com
Tue May 2 18:54:50 EDT 2000


I'm very new to Python, and I've been playing with it quite a bit.
Most of the stuff I've done includes lots of SQL and C shell staff.

I have a tab delimitted file that looks like this ( foo.prn)
=========================================================
19990222      86.8750      88.1250      86.6250      87.9375    24994
19990223      87.6875      87.8750      86.6250      87.3750    16288
19990224      87.0000      87.6875      85.7500      85.7500    18013
19990225      84.7500      85.0000      83.3750      84.4375    25336
=========================================================

I want to insert this file to database table called  format_prices with
fields (time,open,high,low,close,volume)
I'm using mxODBC module in win32.

I created a function that reads the file and puts the contents into a list
======================================================
def read_his_file(s):
 #make sure we are in the d:\__newstocks__ directory
 import os, string, sys
 os.chdir("d:\__newstocks__")
 lines = open(s).readlines()

 #get rid of new line character and white spaces
 lines = map(string.split, lines)
 table = []

 #get rid of the header
 lines = lines[1:]
 for i in lines:
  prn = i[:-1]
  table.append(prn)

 return table
 =======================================================

Now I get this list [['19990222', '86.8750', '88.1250', '86.6250',
'87.9375', '24994'].......]

How do I loop thru the list and insert the date into format_prices?
Is there some docs or tutorial that talks about issues like manipulating
database with python.?

In advance ,thanks a lot for all your help.


Arnaldo






More information about the Python-list mailing list