Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

access sqlite db python

import sqlite3
import os.path

#Connection to the DB
try:
    # Make sure to find the file.db in the script directory
    BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
    db_path = os.path.join(BASE_DIR, "sqlite.db")
    conn = sqlite3.connect(db_path)

except sqlite3.Error as error:
    print("Failed to read data from sqlite table", error)



# Execute query on the sqlite DB
cur = conn.cursor()
cur.execute("SELECT * FROM tasks")

# Print everything from a table
rows = cur.fetchall()
for row in rows:
        print(row)
    
# Update field 
conn.execute("""UPDATE tasks SET name = 'jhon'
 where id = 1""")

# close the DB connection 
conn.close() 
Comment

PREVIOUS NEXT
Code Example
Python :: pygame key pressed once 
Python :: python convert string to float array 
Python :: urllib urlretrieve python 3 
Python :: or operator django 
Python :: Taking a list of strings as input, our matching function returns the count of the number of strings whose first and last chars of the string are the same. Also, only consider strings with length of 2 or more. python 
Python :: how to save a python object in a file 
Python :: python - remove columns with same name and keep first 
Python :: import time in python 
Python :: count unique pandas 
Python :: pandas get day names 
Python :: setting p a virtual envioronment 
Python :: pickle.dump python 
Python :: isdigit in python 
Python :: strip array of strings python 
Python :: how to find the last item of a list 
Python :: hardest python questions 
Python :: python read entire file 
Python :: get span text selenium python 
Python :: python 2 is no longer supported 
Python :: get mode dataframe 
Python :: split a variable into multiple variables in python 
Python :: prime number in python 
Python :: split column by comma pandas 
Python :: place legend on location matplotlib 
Python :: django clear all sessions 
Python :: pandas max columns 
Python :: pil normalize image 
Python :: how to take input in python3 separated by space 
Python :: python list count() 
Python :: dataframe standardise 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =