On Tue, 12 Aug 2008 05:51:19 -0700, Mike P wrote: > Hi All, > > I've been given a Perl script that i'm trying to convert into python. > The aim of the script links to MqSQL database, but i'm stuck on one > part > > my $sth = $dbh->prepare($sql)|| > die "Could not prepare SQL statement ... maybe invalid?:$!\n$sql > \n"; > $sth->execute()|| > die "Could not execute SQL statement ... maybe invalid?:$!\n$sql > \n"; > > while (my @row= $sth->fetchrow_array()) { > my $combined = join(",", @row); > print "$combined\n"; > } > > I don't know much MySQL or Perl.. > > Can anyone help to convert this for me? > > Mike
You could try something like: cursor=db.cursor() cursor.execute(sql) while (1): row = cursor.fetchone() if row == None: break combined = ', '.join(row) This has NOT been tested. More info available at http://www.kitebird.com/articles/pydbapi.html and lots of other pages. Googling for "MySQLdb" should get you a decent list. -- http://mail.python.org/mailman/listinfo/python-list