python equivalent of php implode

Maksim Kasimov kasimov at i.com.ua
Wed Apr 27 03:04:26 EDT 2005


... but not in the case when integers are in a dictionary (please, try to
execute your example by yourself first)


"Ola Natvig" <ola.natvig at infosense.no> wrote:
news:kvo3k2-s9c.ln1 at pluto.i.infosense.no...
> 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