Re: BACK: Inserting a variable into cur.execute statement

From: Vladimir Ryabtsev <greatvovan(at)gmail(dot)com>
To: hagen(at)datasundae(dot)com
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, psycopg(at)lists(dot)postgresql(dot)org, psycopg(at)postgresql(dot)org
Subject: Re: BACK: Inserting a variable into cur.execute statement
Date: 2020-12-21 02:44:24
Message-ID: CAMqTPqmD-Xp3Ab1PPxCeezWyGFYrU1bNCrrc=9L9NQbXvHHYOw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

> 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, <hagen(at)datasundae(dot)com> wrote:

> Interesting - thank you Adrian.
>
> -----Original Message-----
> From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
> Sent: Sunday, December 20, 2020 5:57 PM
> To: Hagen Finley <hagen(at)datasundae(dot)com>; psycopg(at)lists(dot)postgresql(dot)org;
> psycopg(at)postgresql(dot)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(dot)klaver(at)aklaver(dot)com
>
>
>
>

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2020-12-21 14:24:37 psycopg3, prepared statements
Previous Message hagen 2020-12-21 01:21:11 RE: BACK: Inserting a variable into cur.execute statement