[Tutor] My code to update database

Emile van Sebille emile at fenx.com
Fri Jul 10 20:51:35 CEST 2009


On 7/10/2009 11:29 AM Eduardo Vieira said...
> Hello! I have the code below to update a database from a csv file. I
> have tested one time and it has worked fine, but I'm a bit fearful
> that it should work right as I am updating a database and don't want
> to cause troubles into the system.
> Is this code safe for my personal use?

Looks OK to me -- note one small change I'd make (move myconn and 
mycursor to after __main__ test) , but even that's not critical.

> the update code is in a function, but the rest of the code to connect
> and disconnect is outside the function. I thought this was a good idea
> because for each line iterated in the csv file, there is a call to the
> function to update the database with the data from the csv file. So,
> using the 'global' inside the function is ok, or maybe not?

Looks like you don't need the global at all.  Have you tried without it?


Emile



More information about the Tutor mailing list