Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.15 KB

USAGE.md

File metadata and controls

53 lines (38 loc) · 1.15 KB

Python

CSV

To import in a file object, we recommend using DictReader

from csv import DictReader

data = []
with open("sandbox/dictionary.csv") as file:
    rows = DictReader(file)
    for row in rows:
        data.append(row)
        
# produces a list of dictionaries where each element is organised as
# {"word":"word", "wordtype": "type of word", "definition": "definition of word"}
print(data) 

However, you can also use a generic CSV reader to import the data as a list of lists

from csv import reader

data = []
with open("sandbox/dictionary.csv") as file:
    rows = reader(file)
    for row in rows:
        data.append(row)
        
# produces a list of lists where each element is organised as
# [word, wordtype, definition]
print(data) 

SQLite3

To import in a python script using SQLite3 library, follow the instructions below

import sqlite3 as SQL

conn = SQL.connect("sqlite3/dictionary.db") #Or change to other path-to-.db-file
db = conn.cursor()

# Sample Usage
db.execute("SELECT * from entries")
output = db.fetchall()
print(output)
db.close()