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 1nbUrZ-0006tj-Bj for psycopg@arkaria.postgresql.org; Mon, 04 Apr 2022 22:07:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nbUrY-0006Gb-4J for psycopg@arkaria.postgresql.org; Mon, 04 Apr 2022 22:07:52 +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 1nbUrX-0006Fi-Ow for psycopg@lists.postgresql.org; Mon, 04 Apr 2022 22:07:51 +0000 Received: from smtp102.ord1c.emailsrvr.com ([108.166.43.102]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbUrV-0008JO-2I for psycopg@postgresql.org; Mon, 04 Apr 2022 22:07:50 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp21.relay.ord1c.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 2C38EC015E; Mon, 4 Apr 2022 18:07:47 -0400 (EDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_BD02A9D7-CC91-434E-B684-1C055FDA17A7" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: cur.execute() syntax error From: Christophe Pettus In-Reply-To: <9471b149-dd21-5040-3693-c6f54ddc3b36@appl-ecosys.com> Date: Mon, 4 Apr 2022 15:07:41 -0700 Cc: psycopg@postgresql.org X-Mailbutler-Message-Id: B46E5FF8-EEFF-42AE-AD29-722FE357E71A Message-Id: <5D9AFC04-EF8C-401F-83EB-98976F898326@thebuild.com> References: <9471b149-dd21-5040-3693-c6f54ddc3b36@appl-ecosys.com> To: Rich Shepard X-Mailer: Apple Mail (2.3608.120.23.2.7) X-Classification-ID: dd05fe18-d743-4552-96ca-9be0c6081864-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_BD02A9D7-CC91-434E-B684-1C055FDA17A7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii It looks like the LabelInput constructor includes some code. Did you = mean something like: self.inputs['Contact Type'] =3D LabelInput( ContactDataForm, 'contact_type',) # query to fetch data from contacttypes table fetch_all =3D "SELECT * from contacttypes" cur.execute(fetch_all) # fetching all rows rows =3D cur.fetchall() input_class=3Dttk.Combobox([values =3D rows]) input_var=3Dtk.StringVar() # get selected value and bind it to a method cont_type =3D self.get() # selected value by mouse click con.close() =20 > On Apr 4, 2022, at 15:02, Rich Shepard = wrote: >=20 > This MWE (test_combobox.py) produces a syntax error and I'm not seeing = why: > ----- > import tkinter as tk > from tkinter import ttk >=20 > import psycopg2 >=20 > class ContactDataForm(tk.Frame): > # set up postgres > # the connection > con =3D psycopg2.connect(database=3D'bustrac') > # the cursor > cur =3D con.cursor() >=20 > def __init__(self, parent, *args, **kwargs): > super().__init__(parent, *args, **kwargs) > # A dict to keep track of input widgets > self.inputs =3D {} >=20 > self.inputs['Contact Type'] =3D LabelInput( > ContactDataForm, 'contact_type', > # query to fetch data from contacttypes table > fetch_all =3D "SELECT * from contacttypes" > cur.execute(fetch_all) > # fetching all rows > rows =3D cur.fetchall() > input_class=3Dttk.Combobox([values =3D rows]) > input_var=3Dtk.StringVar() > # get selected value and bind it to a method > cont_type =3D self.get() # selected value by mouse click > con.close() > ) > self.inputs['Contact Type'].grid(row0, column1) > ContactDataForm.grid(row=3D0, column=3D0, sticky=3D'we') > ----- >=20 > When run from the shell: > $ python test_combobox.py > File "test_combobox.py", line 24 > cur.execute(fetch_all) > ^ > SyntaxError: invalid syntax >=20 > Here python is python3 by default. >=20 > What am I not seeing? >=20 > Rich >=20 >=20 --Apple-Mail=_BD02A9D7-CC91-434E-B684-1C055FDA17A7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii It looks like the LabelInput constructor = includes some code.  Did you mean something like:

      =  self.inputs['Contact Type'] =3D LabelInput(
           ContactDataForm, = 'contact_type',)
       # query = to fetch data from contacttypes table
    =    fetch_all =3D "SELECT * from contacttypes"
       cur.execute(fetch_all)
       # fetching all rows
       rows =3D cur.fetchall()
       input_class=3Dttk.Combobox([values = =3D rows])
      =  input_var=3Dtk.StringVar()
    =    # get selected value and bind it to a method
       cont_type =3D self.get() # = selected value by mouse click
      =  con.close()
        =    

On Apr 4, 2022, at 15:02, Rich Shepard <rshepard@appl-ecosys.com> wrote:

This MWE (test_combobox.py) produces a syntax error and I'm = not seeing why:
-----
import tkinter as = tk
from tkinter import ttk

import psycopg2

class = ContactDataForm(tk.Frame):
   # set up = postgres
   # the connection
  =  con =3D psycopg2.connect(database=3D'bustrac')
  =  # the cursor
   cur =3D con.cursor()

   def __init__(self, parent, *args, = **kwargs):
      =  super().__init__(parent, *args, **kwargs)
  =      # A dict to keep track of input widgets
       self.inputs =3D {}
       self.inputs['Contact Type'] =3D = LabelInput(
          =  ContactDataForm, 'contact_type',
    =        # query to fetch data from contacttypes = table
           fetch_all =3D= "SELECT * from contacttypes"
        =    cur.execute(fetch_all)
      =      # fetching all rows
    =        rows =3D cur.fetchall()
  =          input_class=3Dttk.Combobox([values =3D = rows])
          =  input_var=3Dtk.StringVar()
      =      # get selected value and bind it to a method
           cont_type =3D = self.get() # selected value by mouse click
    =        con.close()
    =        )
      =  self.inputs['Contact Type'].grid(row0, column1)
 =      ContactDataForm.grid(row=3D0, column=3D0, = sticky=3D'we')
-----

When run = from the shell:
$ python test_combobox.py
 File "test_combobox.py", line 24
  =  cur.execute(fetch_all)
     ^
SyntaxError: invalid syntax

Here = python is python3 by default.

What am I not = seeing?

Rich


= --Apple-Mail=_BD02A9D7-CC91-434E-B684-1C055FDA17A7--