Perl to Python using MqSQLdb

Fredrik Lundh fredrik at pythonware.com
Wed Aug 13 15:58:45 CEST 2008


Mike P wrote:

> That is a nice piece of code,
> 
> I cracked the idea of the shift; problem, my final problem is still
> how to convert
> 
>    my @row = $sth->fetchrow_array;
>    $$StartDate = $row[0];
>    $$EndDate = $row[1];
>    $sth->finish()
> 
> into python code as i'm not sure what $$ means

according to a quick google, fetchrow_array is equivalent to Python's 
fetchone (read one row from the database into a sequence object), so the 
above is simply:

     row = cursor.fetchone()
     start_date = row[0]
     end_date = row[1]

in Python.  if you know for sure that the SQL statement only fetches two 
columns, you can simply do

     start_date, end_date = cursor.fetchone()

</F>




More information about the Python-list mailing list