python 3.x - Interact with external applications -


i want write python script output results (from script) outside textbox.
other program's text box,or webpage's search bar.

try flask if want put web page.

to setup database (sqlite example), use this:

# creating database  import sqlite3 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 script writes result database (sqlite databases can accessed many processes according website, 1 can write @ time though):

# insert values db = ['this triumph', 'im making note here', 'huge success'] el in a:     cur.execute('insert helloworld.mydata values (?)', el) 

and have flask serve those. flask see db youll need initial setup:

# more copy pasta http://flask.pocoo.org/docs/0.10/patterns/sqlite3/ import sqlite3 flask import g  database = '/path/to/test.db'  def get_db():     db = getattr(g, '_database', none)     if db none:         db = g._database = connect_to_database()     return db  @app.teardown_appcontext def close_connection(exception):     db = getattr(g, '_database', none)     if db not none:         db.close() 

but can serve information browser (put on prettiest css pants one):

# check out demo @ http://flask.pocoo.org/ see goes @app.route('/') def index():     cur = get_db().cursor()     cur.execute('select helloworld.mydata')      return "<p>{}</p>".format(cur.fetchall()) 

disclaimer, put in past couple minutes, didnt test out of yet. should started.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -