Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93004 > unrolled thread

Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard

Started byTim Chase <python.list@tim.thechases.com>
First post2015-06-22 06:51 -0500
Last post2015-06-22 06:51 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard Tim Chase <python.list@tim.thechases.com> - 2015-06-22 06:51 -0500

#93004 — Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard

FromTim Chase <python.list@tim.thechases.com>
Date2015-06-22 06:51 -0500
SubjectRe: Issuing a sqilte query, picking a random result, and copying to the system clipboard
Message-ID<mailman.706.1434978637.13271.python-list@python.org>
On 2015-06-21 17:08, John T. Haggerty wrote:
> I'm looking to just have a simple program that will do a SQLite
> query pull a random record and then copy that record too the
> clipboard the system. I'm not quite seeing how to do this perhaps
> this is already been done elsewhere but I spent quite a bit of time
> trying to figure out how to do that and I'm not seeing a listing
> anywhere. any help would be greatly appreciated.

First, connect to your data source and obtain a cursor:

  import sqlite3
  conn = sqlite3.connect('file.sqlite')
  cur = conn.cursor()

then select a random row:

  cur.execute("SELECT * FROM table ORDER BY RANDOM() LIMIT 1")
  data = cur.fetchone()

then things get tricky because you don't specify what OS you have, as
there are plenty of occasions when there is no system clipboard.

On Win32, you'd need the Win32 add-on libraries to shove things onto
the clipboard, while under X, you'd need other facilities (either
using Tkinter or piping to something like xclip(1)), and yet another
way of doing things on MacOS.

-tkc



[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web