Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:10:22+00:00 2026-06-09T20:10:22+00:00

When using pythons sqlite3 module, if I were to create a table and the

  • 0

When using pythons sqlite3 module, if I were to create a table and the first row had say 4 columns would the next row have to have 4 columns or could I have more/less?

I’m looking to create a database of vocabulary words. Each word may have a varying number of definitions.

For example ‘set’ would have many more definitions than ‘panacea’.

I would work this vocabulary database in with a scraper that could easily look up the word and definition from a dictionary-reference site.

#! /usr/bin/env python
import mechanize
from BeautifulSoup import BeautifulSoup
import sys
import sqlite3

def dictionary(word):
    br = mechanize.Browser()
    response = br.open('http://www.dictionary.reference.com')
    br.select_form(nr=0)
    br.form['q'] = word 
    br.submit()
    definition = BeautifulSoup(br.response().read())
    trans = definition.findAll('td',{'class':'td3n2'})
    fin = [i.text for i in trans]
    query = {}
    for i in fin: 
        query[fin.index(i)] = i

    ## The code above is given a word to look up and creates a 'dict' of its definiton from the site.

    connection = sqlite3.connect('vocab.db')
    with connection:
        spot = connection.cursor()

        ## This is where my uncertainty is.  I'm not sure if I should iterate over the dict values and 'INSERT' for each definition or if there is a way to put them in all at once? 

        spot.execute("CREATE TABLE Words(Name TEXT, Definition TEXT)")
        spot.execute("INSERT INTO Words VALUES(word, Definition (for each number of definitions))")

    return query


print dictionary(sys.argv[1]) 

This isn’t an assignment but, more of a personal exercise for learning sqlite3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:10:23+00:00Added an answer on June 9, 2026 at 8:10 pm

    Your design goes against the spirit of relational databases (where Wikipedia defines a relation as “a set of tuples that have the same attributes“), of which sqlite is one.

    The appropriate design here is a table for words and a table for definitions, linked by a foreign key. If your word has no other attributes besides its content, you can get by with skipping the words table and just using the keys from the definitions table.

    Note, however, that you’ll have one row per definition, not one per word.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table created using Python + Sqlite3 c.execute('CREATE TABLE IF NOT EXISTS
What would be faster; searching a sqlite3 database table for a row whose primary
Whenever I try to create a table using python and sqlite3, it gives me
I have a table ZZZ with Columns A,B,C,D I am selecting first X rows
I am using pythons built-in sqlite3 module to access a database. My query executes
I am using sqlite3 in python. I have two tables with id column in
hi i am working on a django python application using sqlite3 database. I have
I'm using the sqlite3 module in Python 2.6.4 to store a datetime in a
I have a project built in Python 2.7, using SQLite3 as the database. I
I'm using Python 2.6.4 and its module sqlite3 for a small database project and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.