[Tutor] database question

2007-06-29 Thread Luke Jordan

I've created a database as a shelve, where each value in the shelve file is
a record class instance that has attributes representing fields. Let's say I
enter 300 records in the shelve, then I decide to add a field to future
records, or remove a field from future records. How can I update the
existing records to include the new fields?

Thanks,

Luke


--
If you think that was good, wait 'til you taste the antidote!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] database question

2006-10-27 Thread euoar
I'm learning to use python with  the database mysql. I'm writing a 
widget in pygtk that should show the results of a sql query. For example 
with SELECT * FROM a, I use this code
count = 0
a = db.cursor.description
for tuple in a:
print tuple[0][0]
count = count + 1


... to know how many columns are in the result, and then, what I have to 
do is to create a liststore with  count columns. The method to create 
a ListStore is: liststore = gtk.ListStore(str, str, str, ...[number of 
columns]). I was wondering how to create the liststore with the proper 
number of columns, if there would a way to do something like this with 
python:

# to store the number of columns that will be needed
count = 0
a = db.cursor.description
for tuple in a:
print tuple[0][0]
count = count + 1
   
# this is the string with the method to execute
method_string = gtk.ListStore(
for var in range(count):
method_string = function_string + str,
  
function_string = function_string + )

# is there something like this execute_function?
list_store = execute_function(method_string)


Thank you very much for your advices.


__ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] database question

2006-10-27 Thread Alan Gauld
 For example
 with SELECT * FROM a, I use this code

 ... to know how many columns are in the result,

As a general rule its better to avoid Select * From in production 
SQL.
If the table definition changes the data returned can change in 
unexpected
ways and break your application. In addition you can wind up sucking
up an awful lot of unnecessary data (think bandwidth and server 
throughput).
Its much safer to  explicitly list all of the columns you want to pull 
back
if at all possible.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


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