public inbox for [email protected]  
help / color / mirror / Atom feed
cur.execute() syntax error
3+ messages / 2 participants
[nested] [flat]

* cur.execute() syntax error
@ 2022-04-04 22:02  Rich Shepard <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Rich Shepard @ 2022-04-04 22:02 UTC (permalink / raw)
  To: psycopg

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 = psycopg2.connect(database='bustrac')
     # the cursor
     cur = con.cursor()

     def __init__(self, parent, *args, **kwargs):
         super().__init__(parent, *args, **kwargs)
         # A dict to keep track of input widgets
         self.inputs = {}

         self.inputs['Contact Type'] = LabelInput(
             ContactDataForm, 'contact_type',
             # query to fetch data from contacttypes table
             fetch_all = "SELECT * from contacttypes"
             cur.execute(fetch_all)
             # fetching all rows
             rows = cur.fetchall()
             input_class=ttk.Combobox([values = rows])
             input_var=tk.StringVar()
             # get selected value and bind it to a method
             cont_type = self.get() # selected value by mouse click
             con.close()
             )
         self.inputs['Contact Type'].grid(row0, column1)
         ContactDataForm.grid(row=0, column=0, sticky='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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: cur.execute() syntax error
@ 2022-04-04 22:07  Christophe Pettus <[email protected]>
  parent: Rich Shepard <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Christophe Pettus @ 2022-04-04 22:07 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; +Cc: psycopg

It looks like the LabelInput constructor includes some code.  Did you mean something like:

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

> On Apr 4, 2022, at 15:02, Rich Shepard <[email protected]> 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 = psycopg2.connect(database='bustrac')
>    # the cursor
>    cur = con.cursor()
> 
>    def __init__(self, parent, *args, **kwargs):
>        super().__init__(parent, *args, **kwargs)
>        # A dict to keep track of input widgets
>        self.inputs = {}
> 
>        self.inputs['Contact Type'] = LabelInput(
>            ContactDataForm, 'contact_type',
>            # query to fetch data from contacttypes table
>            fetch_all = "SELECT * from contacttypes"
>            cur.execute(fetch_all)
>            # fetching all rows
>            rows = cur.fetchall()
>            input_class=ttk.Combobox([values = rows])
>            input_var=tk.StringVar()
>            # get selected value and bind it to a method
>            cont_type = self.get() # selected value by mouse click
>            con.close()
>            )
>        self.inputs['Contact Type'].grid(row0, column1)
>        ContactDataForm.grid(row=0, column=0, sticky='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
> 
> 



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: cur.execute() syntax error [RESOLVED]
@ 2022-04-04 22:18  Rich Shepard <[email protected]>
  parent: Christophe Pettus <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Rich Shepard @ 2022-04-04 22:18 UTC (permalink / raw)
  To: psycopg

On Mon, 4 Apr 2022, Christophe Pettus wrote:

> It looks like the LabelInput constructor includes some code.  Did you mean something like:
>
>       self.inputs['Contact Type'] = LabelInput(
>           ContactDataForm, 'contact_type',)
>       # query to fetch data from contacttypes table
>       fetch_all = "SELECT * from contacttypes"
>       cur.execute(fetch_all)
>       # fetching all rows
>       rows = cur.fetchall()
>       input_class=ttk.Combobox([values = rows])
>       input_var=tk.StringVar()
>       # get selected value and bind it to a method
>       cont_type = self.get() # selected value by mouse click
>       con.close()

Christophe,

Sure looks like it.

Thanks,

Rich





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-04-04 22:18 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 22:02 cur.execute() syntax error Rich Shepard <[email protected]>
2022-04-04 22:07 ` Christophe Pettus <[email protected]>
2022-04-04 22:18   ` Re: cur.execute() syntax error [RESOLVED] Rich Shepard <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox