generating SQL - problem

Lee lee.reilly at ntlworld.com
Wed Aug 8 17:07:57 EDT 2001


I wonder if someone could offer me a little advice. I have a large
(155KB) text file holding MP3 data in the format:

Filename with path   ; Title    ; Artistd
d:\\SRS\\Breed.mp3      ; Breed         ; Snake River Conspiracy

I want to parse this file and create a single SQL insert statement, but
I am having a few problems. I have the following script, which works
fine (may not be pretty, but it works ;-)

#
,-----------------------------------------------------------------------------+

# | createMP3SQL.py
# |
# | import string
# |
# | fileobject=open('newdata.txt', 'r')  # open the playlist
# | line = fileobject.readline()          # read the first line
# |
# | FullSQL = ''  # the final query string
# | end = 'false' # test condition - true when end of file is reached
# | while (end!='true'):
# |   try:
# |     line = fileobject.readline()
# |     trackdata=string.split(line, ";")
# |     file=string.rstrip(trackdata[0])
# |     title=string.lstrip(string.rstrip(trackdata[1]))
# |     artist=string.lstrip(string.rstrip(trackdata[2]))
# |     SQL = 'insert into MP3s values (\'' + file + '\', \'' + title +
'\', \''
# |     + artist + '\')'
# |     FullSQL = FullSQL + SQL + ";"
# |   except Exception:
# |     end='true'
#
`-----------------------------------------------------------------------------+

When I run this script is takes ~5 secs to process, and when I type in
'FullSQL' to display the text (the SQL string) in IDLE it halts
completely.  It works fine with smaller test data. I am using Python 2.0
on Win98. Can anyone suggest what the problem is and how it can be
remedied?

Thanks very much in advance,
Lee




More information about the Python-list mailing list