[Tutor] My code to update database
eduardo.susan at gmail.com
Fri Jul 10 22:03:05 CEST 2009
On Fri, Jul 10, 2009 at 12:51 PM, Emile van Sebille<emile at fenx.com> wrote:
> 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.
Well, I thought in the case I needed to import this module then I'd
have to put it there, right?
>> 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?
Oh, yeah, I was getting confuse on that... probably because a another
case where I did need to use the 'global' declaration
More information about the Tutor