[Tutor] Squlite3 problem

2007-03-13 Thread Jim Roush
I'm geting the following error message and I'm stumped

Traceback (most recent call last):
  File C:\markets\source\QuantScan\QuantScan4_3.py, line 1362, in module

db.close()

sqlite3.OperationalError: Unable to close due to unfinalised statements



Here 's the relevant code

db = sqlite.connect('c:/markets/db/market_2.db')
cur_stocks = db.cursor()
cur_quant = db.cursor()
cur_subind = db.cursor()
   
# update ROC table in db
print '\nupdate ROC table in db...\n'
cur = db.cursor()
cur.execute(delete from subind_ROC)
   
for row in range(0, num_of_subinds):
(subind, si_ROC_10, si_ROC_10_1, si_ROC_10_2, si_ROC_20, 
si_ROC_20_1, \
si_ROC_20_2, si_ROC_30, si_ROC_30_1, si_ROC_30_2) = si_ROC[row]

cur.execute(INSERT INTO subind_ROC (subind, ROC_10, ROC_10_1, 
ROC_10_2, ROC_20, ROC_20_1, ROC_20_2, ROC_30, ROC_30_1, ROC_30_2) Values 
(?,?,?,?,?,?,?,?,?,?), (subind, si_ROC_10, si_ROC_10_1, si_ROC_10_2, 
si_ROC_20, si_ROC_20_1, si_ROC_20_2, si_ROC_30, si_ROC_30_1, si_ROC_30_2))

cur.close()
db.commit()
db.close()

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Sorting a list of lists aka nested lists

2005-08-13 Thread Jim Roush
I have a python script that creates a list of lists like so:

Quant.append( [ db_ticker, stock_close, MTD, 0, QTD, 0, YTD, 0, 0, 0 ] )

After Quant is created, I want to sort it by MTD.  If I use a simple 
Quant.sort(), I assume its going to sort by 'db_ticker' which is not 
what I want.

I've been trying to figure out how to use the cmp() in a list sort 
method and I have failed to understand.

Please help.




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.8/71 - Release Date: 8/12/2005

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-13 Thread Jim Roush
Danny Yoo wrote:

On Sat, 13 Aug 2005, Jim Roush wrote:

  

I have a python script that creates a list of lists like so:

Quant.append( [ db_ticker, stock_close, MTD, 0, QTD, 0, YTD, 0, 0, 0 ] )

After Quant is created, I want to sort it by MTD.  If I use a simple
Quant.sort(), I assume its going to sort by 'db_ticker' which is not
what I want.

I've been trying to figure out how to use the cmp() in a list sort
method and I have failed to understand.


 

Hi Jim,

AMK has written a nice mini-tutorial on how to use a list's sort()
effectively:

http://www.amk.ca/python/howto/sorting/sorting.html

Does his tutorial make sense, or are there parts in there that are
baffling?  Please feel free to ask questions on it, and we'll try to help.




  

I actually saw this page this morning, which leads me to believe what I 
want is something like:

Quant.sort(lambda x, y: x-y)

except how does x and y relate to the list of lists I created?


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.8/71 - Release Date: 8/12/2005

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor