python equivalent of php implode
Ola Natvig
ola.natvig at infosense.no
Wed Apr 27 02:44:36 EDT 2005
Maksim Kasimov wrote:
>
> in php-scripts, to insert data to database, i'm doing like this:
>
> ...
> $query_param = array(
> 'field0' => 1,
> 'field1' => 3,
> 'field2' => $var2,
> 'field3' => $var3,
> );
> ...
>
> $sql = "INSERT INTO $table (".implode(", ",
> array_keys($query_param)).") VALUES ('".implode("','", $query_param)."')";
>
> how it can be done, using python (elegantly, without cycles)?
>
>
sql = "INSERT INTO %s (%s) VALUES (%s)" % (table, ','.params.keys()),
','.join(param.values()))
should do the trick.
--
--------------------------------------
Ola Natvig <ola.natvig at infosense.no>
infoSense AS / development
More information about the Python-list
mailing list