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

  • Home
  • SEARCH
  • 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 3945218
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:59:33+00:00 2026-05-20T00:59:33+00:00

I am porting a tcl script to python, because I can’t seem to get

  • 0

I am porting a tcl script to python, because I can’t seem to get the tclSqlite thing going on my Nokia N810. The script prompts for inputs, passes them to a sqlite db with 3 tables: Notes, Tags, and a NotesXTags many-to-many tbl. There are triggers that keep me from storing any tags more than once. Being a noob/hobbyist I went line by line through the tcl script replacing each with a Python line. Not very Pythonic, but I’m a hobbyist with no intention of using the language after I get this one script to work on N810. I did look at every Q&A S.O. suggested and I’ve been working on this for hours. I’ve got at least 3 bugs-of-ignorance. A chunk of the script in a module called ‘pythonmakenote.py’:

the crunch-bang … and some comments ….

import sys, tty
import sqlite3

def mn():
    conn = sqlite3.connect('/home/j...notes.sqlite')
    db = conn.cursor()
tagsofar =db.execute('select tag_text from tag')
print tagsofar

print "Enter note text, remember to let console wrap long lines"
notetxt = input("note: ") 

print "Enter 1 or more tags separated by spaces"
taglist = input("tags: ")
taglist = taglist.split(" ")

db.execute('INSERT INTO note (note_txt) VALUES (?)', notetxt)
db.commit
fknote = db.execute('select last_insert_rowid()')

#records new tags since db trigger stops dups, updates many-many tbl

for tagtxt in taglist: 
    db.execute('INSERT INTO tag VALUES (?)',tagtxt)
    db.commit
    fktag = db.execute('select rowid from tag where tag_text = (?)',tagtxt)
    db.execute('INSERT INTO fkeys VALUES (?,?)',fknote,fktag)
    db.commit

So I do ‘import pythonmakenote’. So far so good. I type ‘mn’ and get an error:

>>> mn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'mn' is not defined

Then I try this:

>>> from pythonmakenote import mn
>>> mn
<function mn at 0xb76b2a74>

But ‘mn’ still doesn’t work. So I remove the Def altogether and copy the file and name it ‘mn.py’ and it sort-of works…

>>> import mn
<sqlite3.Cursor object at 0xb75fb740>
Enter note text, remember to let console wrap long lines
note: 'this is a note'<--------------------------Quotes are a MUST (but not in tcl version)
Enter 1 or more tags separated by spaces
tags: 'dev'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mn.py", line 19, in <module>
    db.execute('INSERT INTO note (note_txt) VALUES (?)', notetxt)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 14 supplied.<-----------------------------Huh?

Where in the world are the S.O. instructions on code block tags and other markdown?

Why can’t I Def mn in a module and use it? Is Python: NameError: global name 'foobar' is not defined pertinent? (to my problem)

I’ve got several other Defs to do for getting notes by tag, getting the tag list, etc.. and I thought they could all go in one module.

I don’t want to put quotes around my inputs (the notes or the space-delimited tag list). Is that doable? I have the import tty thing in there but I’m not using it (don’t know how but I’m beginning to suspect I’ll have to learn)

If I put 3 tags in when prompted, without quotes, I get the ‘unexpected EOF’ error. Why?

I see strings are immutable so maybe assigning the list/split to a var that was a string before could be a problem?

Where does sqlite get ’14’ bindings supplied? I’m splitting on the space char but it’s being ignored (because I’m doing it wrong)?

Would it be easier to do my little project in Bash?

Thanks to anyone who takes the time to get this far. I have a bad habit of needing help in areas off-topic in S.U. and too noob-RTFM here. I struggled a little with the tcl version but it now works like a champ. I expected Python to be somewhat straightforward. Still think it might be.

edit: WOW. A bunch of newlines got stripped out. Sorry I have no idea how to fix. I’m off to see if “raw_input” works better.

  • 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-05-20T00:59:33+00:00Added an answer on May 20, 2026 at 12:59 am

    You’ll want raw_input instead of input in your script. input evaluates what you type, which is why you have to enter quotes.

    You can markdown code using the {} buttons above the input window. That actual markdown for code is a preceding 4 spaces.

    db.commit needs to be db.commit().

    If you do this:

    >>> import pythonmakenote
    

    To run mn do this:

    >>> pythonmakenote.mn()
    

    You can also do:

    >>> from pythonmakenote import mn
    >>> mn()
    

    For lines like:

    db.execute('INSERT INTO note (note_txt) VALUES (?)', notetxt)
    

    You need:

    db.execute('INSERT INTO note (note_txt) VALUES (?)', (notetxt,))
    

    execute expects a sequence, so if you pass a string, it acts as a sequence of single characters, hence your 14 bindings error (it was a string of 14 characters). (xxx,) is the syntax for a 1-element tuple. Making it a list [xxx] would work too.

    Here’s my best guess at something that works. I don’t have your database:

    import sys
    import sqlite3
    
    def mn():
        conn = sqlite3.connect('data.db')
        db = conn.cursor()
        db.execute('select tag_text from tag')
        tagssofar = db.fetchall()
        print tagssofar
    
        print "Enter note text, remember to let console wrap long lines"
        notetxt = raw_input("note: ") 
    
        print "Enter 1 or more tags separated by spaces"
        taglist = raw_input("tags: ")
        taglist = taglist.split()
    
        db.execute('INSERT INTO note (note_txt) VALUES (?)', [notetxt])
        conn.commit()
        db.execute('select last_insert_rowid()')
        fknote = db.fetchone()[0]
        print fknote
    
        #records new tags since db trigger stops dups, updates many-many tbl
    
        for tagtxt in taglist: 
            db.execute('INSERT INTO tag VALUES (?)',[tagtxt])
            conn.commit()
            db.execute('select rowid from tag where tag_text = (?)',[tagtxt])
            fktag = db.fetchone()[0]
            print fktag
            db.execute('INSERT INTO fkeys VALUES (?,?)',[fknote,fktag])
            conn.commit()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am planning on porting a PHP application over to Python. The application is
I'm porting some MATLAB functions to Scilab . The cool thing is that there
Im porting some calculation routines from .Net to Java but there seem to be
While porting an application from SQL 2005 to SQL Server Compact Edition, I found
While porting a desktop application to windows mobile I've reached the following error: Error
Im porting a project from php to java. The project is a web-app based
I'm working on porting a Visual C++ application to GCC (should build on MingW
I am porting a game, that was originally written for the Win32 API, to
I'm porting old VB6 code that uses the Winsock control to C#. I haven't
I'm porting a Java library to C#. I'm using Visual Studio 2008, so I

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.