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 - remove columns with same name and keep first 
:: import time in python 
Python :: pandas count unique values in column 
Python :: python create sqlite db in memory 
Python :: heroku python version 
Python ::  
Python :: select non nan values python 
Python :: calculate days between two dates python 
Python :: pandas column name equal to another column value 
Python :: how to add header in csv file in python 
Python :: Iterating With for Loops in Python Using range() and len() 
Python ::  
Python :: python 2 deprecated 
Python :: 13 pseudo random numbers between 0 to 3 python 
Python :: lexicographic order python 
Python :: basic tkinter window 
Python :: tensor get value 
Python :: how to create numpy array using two vectors 
Python :: python Correlation matrix of features 
Python :: read binary image python 
:: pygame how to find the full screen mode 
Python :: move all files in directory with shutils 
Python :: show equation using geom_smooth 
Python :: aes in python 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =