Python Forum
Help with passing values in npyscreen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with passing values in npyscreen
#8
Now I downloaded Rich and I'm trying to put my inventory.db into a table.

I have this:
from rich.console import Console
from rich.table import Table
import sqlite3

#Connect to the inventory database (inventory.db)
connection = sqlite3.connect("inventory.db")
cursor = connection.cursor()

cursor = connection.cursor()
#Display all records in the Items Table:
cursor.execute('select * from items')

#Get all info from the Items Table
result = cursor.fetchall()

table = Table(title="Item Display")

table.add_column("Name", justify="right", style="cyan", no_wrap=True)
table.add_column("Quantity", style="magenta")
table.add_column("Price($)", justify="right", style="green")
table.add_column("Sell Price($)", justify="right", style="blue")

for row in result:
    table.add_row(row[1],row[2],row[3],row[4])

connection.close()

console = Console()
console.print(table)
But when I run it I get this error:
Error:
line 460, in add_row raise errors.NotRenderableError( rich.errors.NotRenderableError: unable to render int; a string or other renderable object is required
The reason I get this error is because I take in Quantity and Price as an INT. I need those values to be INTs because I do caluclations with them later on.

My question is, how do I work around this error, so I can display my Quantity, Price, and Sell_Price?

Thanks.




This is my CreateTable.py so you can see how my inventory.db is formatted :
import sqlite3

def createDatabase():
        #Create a database (inventory.db)
        connection = sqlite3.connect("inventory.db")
        cursor = connection.cursor()

        table = """CREATE TABLE IF NOT EXISTS Items
                (ID INTEGER PRIMARY KEY  AUTOINCREMENT,
                NAME           TEXT    NOT NULL,
                Quantity       INT     NOT NULL,
                Price          DOUBLE  NOT NULL,
                Sell_Price     DOUBLE,
                Description    TEXT,
                Category       TEXT,
                Location       TEXT    NOT NULL,
                Length_Ft      INT,
                Barcode        INT,
                Image          BLOB,
                Date Updated   datetime default current_timestamp);"""

        #Execute the creation of the table
        cursor.execute(table)
        #print("The database has been created")
        #Commit the changes
        connection.commit()
        #Close the connection
        connection.close() 
Reply


Messages In This Thread
Help with passing values in npyscreen - by Extra - May-14-2022, 02:25 PM
RE: Help with passing values in npyscreen - by Extra - May-21-2022, 12:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved]Return values from npyscreen Extra 2 1,250 Oct-09-2022, 07:19 PM
Last Post: Extra
  Passing Values of Dictionaries to Function & Unable to Access Them firebird 3 2,668 Aug-03-2019, 10:25 PM
Last Post: firebird

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020