Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krBBg-00047C-Ia for psycopg@arkaria.postgresql.org; Mon, 21 Dec 2020 02:44:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1krBBf-00071W-Hm for psycopg@arkaria.postgresql.org; Mon, 21 Dec 2020 02:44:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krBBf-00071P-Ah for psycopg@lists.postgresql.org; Mon, 21 Dec 2020 02:44:39 +0000 Received: from mail-vk1-xa31.google.com ([2607:f8b0:4864:20::a31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1krBBd-0004Q3-5y for psycopg@lists.postgresql.org; Mon, 21 Dec 2020 02:44:38 +0000 Received: by mail-vk1-xa31.google.com with SMTP id t16so1944117vkl.10 for ; Sun, 20 Dec 2020 18:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3QrNXZgkfGjo88jKfskMLtTpoyw9cyeN/IvIwt+1xUU=; b=q9xcO0Q+BWIhzm6SpRakVjNDrK41VV/vK4Bk/EqqrSChdQedWRdImB1D4lP8WVEgCp q+TE3odOQPAhKod5ZCOh8yWGoe31SXUJMAa96m/6zgmBOh3rf5FQ2BTKFP57cBUalpjJ XS/Ia580DfN3kbV/1BpNzzjZUF2PU/LZhjXnlltBXw0U655BS83uA0O+E2/pd3+JjVpm dgkk9l0U+KJU8KYBpXMjc/Ynx3OZ98SQeJ5Tl2DDiTPbRYNpZIVy0vLsoDaR+cfxsGeC v8COEd34RPJjERnNZnfIW9FOmkvol7N/HSusxkNp1HODTSeZZAHw9I6VmmtlLa/F7DBv 81Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3QrNXZgkfGjo88jKfskMLtTpoyw9cyeN/IvIwt+1xUU=; b=dAo5zEBv+Cg4WpLcwvEgWggNe9zdfhOCJbrI4pLhMIZSb/G/l2fZWZ2VgyIy+cM2xd osW5S9yYXHC9xwA2VrnHKj0GK/ge1FqaotvdvZGr3mmFXmRVg3KATbz6VYzq6oyhM0dn gbYp4nUDpK5ayru3gRaw9dZ4Npq9jFjaTd6m6T+wvOl6+BhtxjxPFcdPqXkGtVC0SNwh tjsVcuf+zWSHFMkWrP8KE4sd2QDLx8NTi9BDRQqzR8mINFMGVX41HT3aSHWfq5gwmbtr Qz/dutfQ3kUg32DmxxsDbUjTVO8qTkKcl/uTz4uyIkS8RfPejAHXEuJIoi7oLTywAvce qayg== X-Gm-Message-State: AOAM532ET6Say+JH8paZCymuFei0R4LiTXzAwUsVSLF5YOAYLLCgzw8a 0uMmzUjng3SIcfVS0ebq4YV3VrwLgRoW5XgilqM= X-Google-Smtp-Source: ABdhPJwKZ6tAqatqABWB1SBVejMCXtntPIDecTd62IPa59M/UDRsmzHEZQJhydYthEoQVfRltRF/mFens41HBCtQ4oU= X-Received: by 2002:a1f:2d4d:: with SMTP id t74mr1553103vkt.0.1608518675979; Sun, 20 Dec 2020 18:44:35 -0800 (PST) MIME-Version: 1.0 References: <0bef01d6cce4$987d8120$c9788360$@datasundae.com> <5c55fb91-0b03-2077-fce7-38f2dcc0d402@aklaver.com> <0bf801d6cce8$011969d0$034c3d70$@datasundae.com> <63f9baec-b185-3278-e8a7-84692579f9d8@aklaver.com> <1a5001d6d737$91f209e0$b5d61da0$@datasundae.com> In-Reply-To: <1a5001d6d737$91f209e0$b5d61da0$@datasundae.com> From: Vladimir Ryabtsev Date: Sun, 20 Dec 2020 18:44:24 -0800 Message-ID: Subject: Re: BACK: Inserting a variable into cur.execute statement To: hagen@datasundae.com Cc: Adrian Klaver , psycopg@lists.postgresql.org, psycopg@postgresql.org Content-Type: multipart/alternative; boundary="0000000000004bdf7f05b6f07003" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000004bdf7f05b6f07003 Content-Type: text/plain; charset="UTF-8" > FYI, the above can be simplified to: > > def_acct_analysis(p[0], p[1]) Which, in turn, can be simplified to def_acct_analysis(*p) On Sun, 20 Dec 2020 at 17:21, wrote: > Interesting - thank you Adrian. > > -----Original Message----- > From: Adrian Klaver > Sent: Sunday, December 20, 2020 5:57 PM > To: Hagen Finley ; psycopg@lists.postgresql.org; > psycopg@postgresql.org > Subject: Re: BACK: Inserting a variable into cur.execute statement > > On 12/20/20 3:13 PM, Hagen Finley wrote: > > Hello, > > > > I finally got around to trying to implement this code and I am running > > into an "IndexError: tuple index out of range" problem. > > > > I am running a function with parameters from a list: > > > > def def_acct_analysis(sht,acct): > > print(param[par][0]) > > print(param[par][1]) > > sheet ="sheet"+str(sht) > > print(sheet) > > account = acct > > print(account) > > > > par =0 param = [(1,'ACCT0'),(2,'ACCT1'),(3,'ACCT2'),] > > > > for pin param: > > def_acct_analysis(param[par][0], param[par][1]) > > > > par +=1 > > > FYI, the above can be simplified to: > > param = [(1,'ACCT0'),(2,'ACCT1'),(3,'ACCT2'),] > > for p in param: > def_acct_analysis(p[0], p[1]) > > > > > #Print statements above output: > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > > > --0000000000004bdf7f05b6f07003 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> FYI, the above can be simplified to:
>
>=C2=A0 =C2=A0 =C2=A0def_acct_= analysis(p[0], p[1])

Which, in turn, can be simplifi= ed to

=C2=A0 =C2=A0 =C2=A0def_acct_analysis(*p)

On Sun, 20 Dec 2020 at 17:21, <hagen@datasundae.com> wrote:
Interesting - thank you Adrian.

-----Original Message-----
From: Adrian Klaver <adrian.klaver@aklaver.com>
Sent: Sunday, December 20, 2020 5:57 PM
To: Hagen Finley <hagen@datasundae.com>; psycopg@lists.postgresql.org; psycopg@postgresql.org
Subject: Re: BACK: Inserting a variable into cur.execute statement

On 12/20/20 3:13 PM, Hagen Finley wrote:
> Hello,
>
> I finally got around to trying to implement this code and I am running=
> into an "IndexError: tuple index out of range" problem.
>
> I am running a function with parameters from a list:
>
> def def_acct_analysis(sht,acct):
>=C2=A0 =C2=A0 =C2=A0 print(param[par][0])
>=C2=A0 =C2=A0 =C2=A0 print(param[par][1])
>=C2=A0 =C2=A0 =C2=A0 sheet =3D"sheet"+str(sht)
>=C2=A0 =C2=A0 =C2=A0 print(sheet)
>=C2=A0 =C2=A0 =C2=A0 account =3D acct
>=C2=A0 =C2=A0 =C2=A0 print(account)
>
> par =3D0 param =3D [(1,'ACCT0'),(2,'ACCT1'),(3,'AC= CT2'),]
>
> for pin param:
>=C2=A0 =C2=A0 =C2=A0 def_acct_analysis(param[par][0], param[par][1]) >
>=C2=A0 =C2=A0 =C2=A0 par +=3D1


FYI, the above can be simplified to:

param =3D [(1,'ACCT0'),(2,'ACCT1'),(3,'ACCT2'),]
for p in param:
=C2=A0 =C2=A0 =C2=A0def_acct_analysis(p[0], p[1])

>
> #Print statements above output:
>

--
Adrian Klaver
adrian.klave= r@aklaver.com



--0000000000004bdf7f05b6f07003--