i want to write a python script to output the results i get (from the script) to an outside textbox.
Like an other program's text box,or a webpage's search bar.
            Asked
            
        
        
            Active
            
        
            Viewed 73 times
        
    -1
            
            
        
        Rafael
        
- 7,002
 - 5
 - 43
 - 52
 
        Pentagon98
        
- 123
 - 1
 - 4
 - 10
 
1 Answers
1
            
            
        Try flask if you want it to put it to a web page.
to setup your database (sqlite for example), use something like this:
# creating database
import sqlite3 as lite
import sys
con = None
try:
    con = lite.connect('test.db')
    cur = con.cursor()    
    cur.execute('CREATE DATABASE HELLOWORLD;')
    cur.execute('USE DATABASE HELLOWORLD;')
    cur.execute('CREATE TABLE HELLOWORLD.MYDATA(ID INT PRIMARY KEY AUTOINCREMENT, CONTENT TEXT NOT NULL,);')
except lite.Error, e:
    print "Error %s:" % e.args[0]
    sys.exit(1)
finally:
    if con:
        con.close()
Then change your script so that it writes its result to this database (sqlite databases can be accessed by many processes according to their website, only one can write at a time though):
# insert values into db
a = ['this is a triumph', 'im making a note here', 'huge success']
for el in a:
    cur.execute('insert into HELLOWORLD.MYDATA values (?)', el)
and then have flask serve those. for flask to see the db youll need to do some initial setup:
# more copy pasta from http://flask.pocoo.org/docs/0.10/patterns/sqlite3/
import sqlite3
from flask import g
DATABASE = '/path/to/test.db'
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = connect_to_database()
    return db
@app.teardown_appcontext
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.close()
but then you can serve that information to a browser (put on your prettiest css pants for this one):
# check out the demo at http://flask.pocoo.org/ to see where this goes
@app.route('/')
def index():
    cur = get_db().cursor()
    cur.execute('SELECT ALL FROM HELLOWORLD.MYDATA')
    return "<p>{}</p>".format(cur.fetchall())
Disclaimer, I just put this together in the past couple minutes, i didnt actually get to test out any of this yet. But this should definitely get you started.
        Dave Ankin
        
- 1,060
 - 2
 - 9
 - 20