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 8332501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:44:33+00:00 2026-06-09T02:44:33+00:00

I am writing a small python script like this: #!/usr/bin/env python from sqlite3 import

  • 0

I am writing a small python script like this:

#!/usr/bin/env python

from sqlite3 import dbapi2 as sqlite
from sys import argv,exit

db_name = "hashez.db"

def define_db():
    try:
        conn = sqlite.connect(db_name)
    except IOError as e:
        print "problem while creating/connecting the db:",e.args[0]
        exit(1)

    return conn

def write_db(conn,cursor,na,ha):
    conn.execute("CREATE TABLE IF NOT EXISTS user (name TEXT UNIQUE, hash TEXT UNIQUE)")
    query = "INSERT OR REPLACE INTO user VALUES($name,$hash)"
    cursor.execute(query,[na],[ha])
    cursor.close()  
    conn.commit()
    conn.close()
    exit(0)

if __name__ == "__main__":
    if len(argv) == 2:
        na,ha = argv[1]
        #ha = argv[2]
    else:
        print "no argument given - stopping now"
        exit(1)

    conn = define_db()
    cursor = conn.cursor()
    write_db(conn,cursor,na,ha)

I have no problem when I try to take in one input

python user.py blah

but When I try to do with more than one,It goes into the else loop.

where am I doing the errors? Please guide me thru…

  • 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-09T02:44:34+00:00Added an answer on June 9, 2026 at 2:44 am

    You get this error because the first argument is actually the file name.

    A simple test file shows how this works:

    [~]$ cat test.py
    from sys import argv
    
    if __name__ == '__main__':
        print argv
        print len(argv)
    [~]$ python test.py one two
    ['test.py', 'one', 'two']
    3
    [~]$ python test.py one
    ['test.py', 'one']
    2
    

    You should also fix your SQL/query

    query = "INSERT OR REPLACE INTO user VALUES(?,?)"
    cursor.execute(query,[na,ha])
    conn.commit()
    

    See the sqlite api docs.

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

Sidebar

Related Questions

I'm writing a small Python script which will periodically pull information from a 3rd
Good day! Today I was writing a small script with Python 3.2.2, and this
I am currently writing a small application with Python (3.1), and like a good
I'm writing a small Python script which requires resolving hosts IPs or domain names.
i'm writing a small script to tweet messages from the monitoring systems. The only
I am in the process of writing a small(er) Python script to automate a
I am writing a small script (in Python) that generates and updates a running
I am writing small application in python which read records from Oracle and insert
I am trying to make a python package alias, by writing a small script
I'm writing a very small Python ORM around boto.dynamodb.layer2 . I would like to

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.