Re: Newbie Question: Obtain element from list of tuples

2011-12-19 Thread alex23
On Dec 19, 4:46 pm, "Frank Millman" wrote: > Am I missing something? No, I seem to be. I have _no_ idea how I got that original syntax to work :| My apologies, DevPlayer's suggestion is much more sensible, although slices are still handy when dealing with groups of values. -- http://mail.pytho

Re: Newbie Question: Obtain element from list of tuples

2011-12-19 Thread HoneyMonster
On Mon, 19 Dec 2011 10:40:06 +1100, Chris Angelico wrote: > On Mon, Dec 19, 2011 at 9:55 AM, HoneyMonster > wrote: >> When the user selects a row and clicks a button, I am using: >> pos = self.grid_1.GetGridCursorRow() to establish which tuple in recs >> is involved, and then pid = recs[pos][4] t

Re: Newbie Question: Obtain element from list of tuples

2011-12-19 Thread DevPlayer
On Dec 19, 1:46 am, "Frank Millman" wrote: > "Steven D'Aprano" wrote in message > > news:4eeea8eb$0$11091$c3e8...@news.astraweb.com... > > > On Sun, 18 Dec 2011 18:35:47 -0800, alex23 wrote: > > >> Pre-namedtuple, I used to like using named slices for this: > > >>     cPID = slice(19) > >>     pi

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Frank Millman
"Steven D'Aprano" wrote in message news:4eeea8eb$0$11091$c3e8...@news.astraweb.com... On Sun, 18 Dec 2011 18:35:47 -0800, alex23 wrote: Pre-namedtuple, I used to like using named slices for this: cPID = slice(19) pid = recs[cPID] You know, that is an incredibly simple thing and ye

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Steven D'Aprano
On Sun, 18 Dec 2011 18:35:47 -0800, alex23 wrote: > Pre-namedtuple, I used to like using named slices for this: > > cPID = slice(19) > pid = recs[cPID] You know, that is an incredibly simple thing and yet it never dawned on me before now. Thank you for sharing that. -- Steven -- ht

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread alex23
Roy Smith wrote: > A common convention > is that when you're unpacking a tuple (or a list, I suppose) and are > only interested in some of the elements, you unpack the others into "_". > Thus: > > _, _, _, _, pid, _, _, _ = recs[19] Pre-namedtuple, I used to like using named slices for this:

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Chris Angelico
On Mon, Dec 19, 2011 at 9:55 AM, HoneyMonster wrote: > When the user selects a row and clicks a button, I am using: > pos = self.grid_1.GetGridCursorRow() to establish which tuple in recs is > involved, and then pid = recs[pos][4] to determine the key value (I > suspected that accessing recs direc

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread HoneyMonster
On Mon, 19 Dec 2011 07:51:08 +1100, Chris Angelico wrote: > On Mon, Dec 19, 2011 at 6:41 AM, HoneyMonster > wrote: >> My question is doubtless a very easy one to answer: Say I want the >> ninth element in the twentieth tuple put into variable PID, I can do >> this, bearing in mind that numbering

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Roy Smith
In article , Chris Angelico wrote: > If you're absolutely certain that you'll always get precisely one > value from a query, this becomes rather more useful: > > mode = conn.query("SELECT mode FROM config WHERE id=5")[0][0] Although, if you're going to do that, you might as well take advantage

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Chris Angelico
On Mon, Dec 19, 2011 at 6:41 AM, HoneyMonster wrote: > My question is doubtless a very easy one to answer: Say I want the ninth > element in the twentieth tuple put into variable PID, I can do this, > bearing in mind that numbering starts at zero: > > tup = recs[19] > PID = tup[8] > > But there mu

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Roy Smith
In article , HoneyMonster wrote: > I think I rather like Python! +1 QOTD? -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread HoneyMonster
On Sun, 18 Dec 2011 15:04:13 -0500, Roy Smith wrote: > In article , > HoneyMonster wrote: > >> Hi, >> >> I'm just starting to learn Python, so please bear with me. I have in my >> program an object (recs) which is a list of tuples (returned as such by >> a database query). > > Sounds like a s

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Roy Smith
In article , HoneyMonster wrote: > Hi, > > I'm just starting to learn Python, so please bear with me. I have in my > program an object (recs) which is a list of tuples (returned as such by a > database query). Sounds like a standard database interface -- each tuple represents one row in the

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Arnaud Delobelle
On 18 December 2011 19:41, HoneyMonster wrote: > Hi, > > I'm just starting to learn Python, so please bear with me. I have in my > program an object (recs) which is a list of tuples (returned as such by a > database query). > > My question is doubtless a very easy one to answer: Say I want the nin

Newbie Question: Obtain element from list of tuples

2011-12-18 Thread HoneyMonster
Hi, I'm just starting to learn Python, so please bear with me. I have in my program an object (recs) which is a list of tuples (returned as such by a database query). My question is doubtless a very easy one to answer: Say I want the ninth element in the twentieth tuple put into variable PID,