Re: python equivalent of php implode

2005-04-27 Thread Dave Cook
On 2005-04-27, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Wed, 27 Apr 2005 08:44:36 +0200, Ola Natvig <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: >> sql = "INSERT INTO %s (%s) VALUES (%s)" % (table, ','.params.keys()), >> ','.join(param.values())) > That also

Re: python equivalent of php implode

2005-04-27 Thread Jeff Epler
On Tue, Apr 26, 2005 at 09:59:29PM -0500, Mike Meyer wrote: > Jeff Epler <[EMAIL PROTECTED]> writes: > > > items = query_param.items() > > keys = [item[0] for item in items] > > values = [item[1] for item in items] > > Is there some reason not to do: > >keys = query_params.keys()

Re: python equivalent of php implode

2005-04-27 Thread Maksim Kasimov
done. thanks Try another paramstyle (see http://python.org/peps/pep-0249.html), e. g. ",".join(["%s"] * len(keys)) ... instead of ",".join(["?"] * len(keys)) ... Peter -- Best regards, Maksim Kasimov mailto: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: python equivalent of php implode

2005-04-27 Thread Peter Otten
Maxim Kasimov wrote: > i'm tying to run example, and then get a traceback. am i something missed? > > mysql> create table tmp_tmp (id int not null auto_increment primary key, > sd varchar(255) not null default '', si int not null default 1); > import MySQLdb db = MySQLdb.connect("local

Re: python equivalent of php implode

2005-04-27 Thread Maksim Kasimov
... but not in the case when integers are in a dictionary (please, try to execute your example by yourself first) "Ola Natvig" <[EMAIL PROTECTED]> wrote: news:[EMAIL PROTECTED] > Maksim Kasimov wrote: > > > > in php-scripts, to insert data to database, i'm doing like this: > > > > ... > > $

Re: python equivalent of php implode

2005-04-27 Thread Maxim Kasimov
i'm tying to run example, and then get a traceback. am i something missed? mysql> create table tmp_tmp (id int not null auto_increment primary key, sd varchar(255) not null default '', si int not null default 1); >>> import MySQLdb >>> db = MySQLdb.connect("localhost", "login", "password", "

Re: python equivalent of php implode

2005-04-26 Thread Ola Natvig
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 ('

Re: python equivalent of php implode

2005-04-26 Thread Mike Meyer
Jeff Epler <[EMAIL PROTECTED]> writes: > items = query_param.items() > keys = [item[0] for item in items] > values = [item[1] for item in items] Is there some reason not to do: keys = query_params.keys() values = query_params.values() That would seem to be a lot more obvious a

Re: python equivalent of php implode

2005-04-26 Thread Jeff Epler
It looks like php's implode(sep, seq) is like sep.join(seq) in Python. But this is a lousy way to write database queries. You should use the Python's DB-API interface's execute(statement, parameters) instead. Assuming that paramstyle is 'qmark', I think it ends up looking something like this:

python equivalent of php implode

2005-04-26 Thread Maksim Kasimov
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("','", $quer