From brett at lunarr.com Wed Sep 5 23:18:49 2007 From: brett at lunarr.com (Brett Josephson) Date: Wed, 5 Sep 2007 14:18:49 -0700 Subject: [portland] LUNARR Demo & Food Message-ID: <61EC8A9A-AD47-4564-9FE6-8515FD6395B5@lunarr.com> After two years in stealth mode, LUNARR of Portland, Oregon is ready to launch an early version of its web-based collaboration software. Join us for a pre-release demo and Q&A at CubeSpace at 622 SE Grand Ave. on September 17 from 6pm to 8pm led by Toru Takasuka, CEO and founder, and Hideshi Hamaguchi, COO. Japanese food and beverages will be provided. Contact Brett Josephson at LUNARR for more information at 503.293.8484 and visit http://about.lunarr.com. The new software is a web-based (browser) system using Javascript/ Scriptalicious on the front end, and Java on the back end, with the usual suspects (jboss, apache, mysql, linux). If you would like to join please RSVP at our upcoming.org page http://upcoming.yahoo.com/event/262001/?ps=5 From freyley at gmail.com Thu Sep 6 18:18:02 2007 From: freyley at gmail.com (Jeff Schwaber) Date: Thu, 6 Sep 2007 09:18:02 -0700 Subject: [portland] Fwd: LUNARR Demo & Food In-Reply-To: <1D224DE7-D14B-4AE3-ACD4-28C3910FB24D@lunarr.com> References: <61EC8A9A-AD47-4564-9FE6-8515FD6395B5@lunarr.com> <8db4a1910709052345t4a55be5dr6ea0bafb89584b99@mail.gmail.com> <1D224DE7-D14B-4AE3-ACD4-28C3910FB24D@lunarr.com> Message-ID: <8db4a1910709060918t32f2404ene875b52d75c4b84c@mail.gmail.com> Hey guys, Sorry about the spam. Here's Brett's reply when I pointed out that it was spam. Jeff ---------- Forwarded message ---------- From: Brett Josephson Date: Sep 6, 2007 9:15 AM Subject: Re: [portland] LUNARR Demo & Food To: Jeff Schwaber Hey Jeff To be quite honest we are not using python language with our product. Our goal, and aim is to get our new product (which we have spent over 2 years developing) in front of Portland's tech community. Our collaboration software could put Portland on the web 2.0 map like never before, and we are looking to share it with people around Portland first. I hope you decide to come to the demo, at the very least its free sushi and beer. Brett On Sep 5, 2007, at 11:45 PM, Jeff Schwaber wrote: > Hey Brett, > > The least you could do, before you spammed us, is considered why we > would care and told us. Is this a python application? Are you hiring? > Is your demo going to talk about the underlying technology? > > If not, what you've just done is pretty clearly not acceptable. > > Thanks, > > Jeff > > On 9/5/07, Brett Josephson wrote: >> After two years in stealth mode, LUNARR of Portland, Oregon is ready >> to launch an early version of its web-based collaboration software. >> Join us for >> a pre-release demo and Q&A at CubeSpace at 622 SE Grand Ave. on >> September 17 from 6pm to 8pm led by Toru Takasuka, CEO and founder, >> and Hideshi >> Hamaguchi, COO. Japanese food and beverages will be provided. Contact >> Brett Josephson at LUNARR for more information at 503.293.8484 and >> visit >> http://about.lunarr.com. >> >> >> The new software is a web-based (browser) system using Javascript/ >> Scriptalicious on the front end, and Java on the back end, with the >> usual suspects (jboss, apache, mysql, linux). >> >> >> If you would like to join please RSVP at our upcoming.org page >> >> http://upcoming.yahoo.com/event/262001/?ps=5 >> >> _______________________________________________ >> Portland mailing list >> Portland at python.org >> http://mail.python.org/mailman/listinfo/portland >> From freyley at gmail.com Thu Sep 6 18:23:23 2007 From: freyley at gmail.com (Jeff Schwaber) Date: Thu, 6 Sep 2007 09:23:23 -0700 Subject: [portland] Upcoming Meeting 9/11/2007 Message-ID: <8db4a1910709060923n69eeaf30y275a991a3d02dcec@mail.gmail.com> Hey folks! It's that time again. We're set to see each other for more lightning talks, more questions, more chit (or chat), and more beer. This coming Tuesday, the 11th, 7pm, Cubespace, and here's what we had from last month: Lightning talks: Jason: PyFlakes Kirby: P4E (Programming for Everyone) Kirby: Programming the Tux Droid Plenty of time for everybody else. Excellent. Anybody's company want to spring for pizza? Jeff From jek at discorporate.us Thu Sep 6 18:52:23 2007 From: jek at discorporate.us (jason kirtland) Date: Thu, 06 Sep 2007 09:52:23 -0700 Subject: [portland] Upcoming Meeting 9/11/2007 In-Reply-To: <8db4a1910709060923n69eeaf30y275a991a3d02dcec@mail.gmail.com> References: <8db4a1910709060923n69eeaf30y275a991a3d02dcec@mail.gmail.com> Message-ID: <46E03047.1010906@discorporate.us> Mark is also on the wiki's agenda for a lightning talk on the Python Imaging Library. Anyone else up? One easy topic that seems kind of fun is the "How I Write Python" 5 minute show and tell- just plug in your laptop and show some code in your editor/IDE of choice. I've heard rumors that some of those new fangled IDEs do pretty smart things for Python development... maybe cool enough to make some of us old cranky Emacs users switch. ;) Jeff Schwaber wrote: > Hey folks! > > It's that time again. We're set to see each other for more lightning > talks, more questions, more chit (or chat), and more beer. This coming > Tuesday, the 11th, 7pm, Cubespace, and here's what we had from last > month: > > Lightning talks: > > Jason: PyFlakes > Kirby: P4E (Programming for Everyone) > Kirby: Programming the Tux Droid > > Plenty of time for everybody else. Excellent. > > Anybody's company want to spring for pizza? > > Jeff > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From jek at discorporate.us Fri Sep 7 00:18:30 2007 From: jek at discorporate.us (jason kirtland) Date: Thu, 06 Sep 2007 15:18:30 -0700 Subject: [portland] learn to program / robots game? Message-ID: Hi all, A 10 year old friend wants to learn about programming. He's on the other side of the country, and I don't have all that much time available to tutor remotely. So I've been thinking about a way to get him a focused introduction that isn't overwhelming or boring. Way back when, there was a great programming game called RobotWar that I remember very fondly. In it you wrote programs that control robot tanks on a battlefield, and the basic skills of programming with functions, variables, etc. come pretty naturally as the player tinkers with their robot for increased longevity and/or lethality. That game is long gone (it's been 25 years? yow.), but I still think that or something like it is a great introduction, especially for an isolated but interested student. I've made a cursory inspection of current variants and I didn't turn up any actively maintained descendants that appealed to me. The big modern one is Java, and I've got misgivings about the accessibility of that one for programming beginners. Does anyone have any suggestions or experience with beginner-friendly programming games? I'd kind of prefer one with a restricted language (to encourage innovation with limited resources), but maybe I'm just being old and crusty. And probably not Internet-based, at least in any socially interactive way. I'm thinking maybe an intro to Python as a second step, probably with pygame. (He wants to write games, of course...) -j From kirby.urner at gmail.com Fri Sep 7 00:39:07 2007 From: kirby.urner at gmail.com (kirby urner) Date: Thu, 6 Sep 2007 15:39:07 -0700 Subject: [portland] learn to program / robots game? In-Reply-To: References: Message-ID: On 9/6/07, jason kirtland wrote: > That game is long gone (it's been 25 years? yow.), but I still > think that or something like it is a great introduction, especially > for an isolated but interested student. I've made a cursory > inspection of current variants and I didn't turn up any actively > maintained descendants that appealed to me. The big modern one is > Java, and I've got misgivings about the accessibility of that one > for programming beginners. Game Maker, which is maybe your "big modern one" is by many accounts quite good, popular with Portland kids, big at Saturday Academy. http://en.wikipedia.org/wiki/Game_Maker This one is also popular, more in the tank genre: http://www.ibm.com/developerworks/java/library/j-robocode/ Pygame is good too, though of course quite low level, just above C++. You have to know how to write game logic already. So maybe cut your teeth on something else first. A lot depends if it's really *game programming* a person wants to learn, or just wants more opportunities to play games, but "learning programming" sounds more like what the dominant big people culture wants to hear. Not that it has to be either/or. Ten is pretty young though. Has anyone checked ToonTalk lately? Way more surreal than Squeak, but still good. http://www.toontalk.com/ I'd also recommend this Tux Droid I'd like to demo on 911 (for under 5 minutes). Crunchy speaks excellent Python (that's my name for her). Kirby From jek at discorporate.us Fri Sep 7 00:59:40 2007 From: jek at discorporate.us (jason kirtland) Date: Thu, 06 Sep 2007 15:59:40 -0700 Subject: [portland] learn to program / robots game? In-Reply-To: References: Message-ID: <69AA7F26730BEDD007CD1702@[10.8.15.22]> kirby wrote: > Game Maker, which is maybe your "big modern one" is by many > accounts quite good, popular with Portland kids, big at > Saturday Academy. > > http://en.wikipedia.org/wiki/Game_Maker Thanks, I hadn't seen that one. It looks pretty promising! "robocode" was the "big" robot one I was thinking of, and the community around it seems pretty hard-core and seasoned, too much so. > A lot depends if it's really *game programming* a person wants > to learn, or just wants more opportunities to play games, but > "learning programming" sounds more like what the dominant > big people culture wants to hear. > > Not that it has to be either/or. > > Ten is pretty young though. This kid seems pretty interested in the creative aspects, hoping to be able to someday realize his visions as movies or games and seeing programming as a means to an end. I was originally thinking about scriptable VR environments, but without multi-user that just seems too lonely and undirected an introduction. Something like Second Life would probably work, if it weren't for all the other people and their content... > Has anyone checked ToonTalk lately? > Way more surreal than Squeak, but still good. > > http://www.toontalk.com/ That has potential too. Thanks! From robin at alldunn.com Fri Sep 7 04:49:26 2007 From: robin at alldunn.com (Robin Dunn) Date: Thu, 06 Sep 2007 19:49:26 -0700 Subject: [portland] learn to program / robots game? In-Reply-To: References: Message-ID: <46E0BC36.4060803@alldunn.com> jason kirtland wrote: > Does anyone have any suggestions or experience with > beginner-friendly programming games? I'd kind of prefer one with a > restricted language (to encourage innovation with limited > resources), but maybe I'm just being old and crusty. And probably > not Internet-based, at least in any socially interactive way. > > I'm thinking maybe an intro to Python as a second step, probably > with pygame. (He wants to write games, of course...) > I haven't done much more than a a quick browse of this, but it looks good. http://rur-ple.sourceforge.net/en/rur.htm -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! From freyley at gmail.com Wed Sep 12 20:07:00 2007 From: freyley at gmail.com (Jeff Schwaber) Date: Wed, 12 Sep 2007 11:07:00 -0700 Subject: [portland] Code Sprint Wed Sep 19th In-Reply-To: <8db4a1910709121059o3bfe35a7w93606d115f1dc588@mail.gmail.com> References: <8db4a1910709121059o3bfe35a7w93606d115f1dc588@mail.gmail.com> Message-ID: <8db4a1910709121107n4aa8dbe8t7f924a842f5fe590@mail.gmail.com> Hey Pythoneers, Come and code with us! Python's a perfect language for code sprints, and I hope to see you all there next week. Code Sprint Wednesday, September 19th, 7pm-9pm CubeSpace - http://www.cubespacepdx.com has directions and parking info on it. Sign up on the wiki: http://code.arlim.org/wiki Thanks, Jeff PS: I'm hoping to start a trend where when something of import is mentioned at the meeting it has a follow-up email. Anybody else got one? From freyley at gmail.com Wed Sep 12 23:26:37 2007 From: freyley at gmail.com (Jeff Schwaber) Date: Wed, 12 Sep 2007 14:26:37 -0700 Subject: [portland] Next Meeting Message-ID: <8db4a1910709121426w6e9dadbflf9c4e055321674e4@mail.gmail.com> Hey Pythoneers, Jason said he'd get the list of topics on the wiki from the pieces of paper we had -- or at least, the half that were farthest to the right. Look forward to those soon. Michelle reminded us that there's an IRC channel, #pdxpython on Freenode. Between these two things and the mailing list we should be able to figure out some projects that have the most interest for small group gatherings for next time. I think, with the number of people we've got, that we'll want to narrow it to about 4-5 projects, and we'll want each project to try to report back so we can all share. It would also be great if anyone felt they weren't particularly attached to one project and wanted to act as historian and bump around the room looking for things to report that wouldn't otherwise be remembered. With that, I'm going to start it off by saying that what I'd really like to do next time is take somebody's codebase (I'm looking at you, Kevin) and attack it with pester (jester.sourceforge.net). If this sounds like something you'd be interested in helping with, let me know. What are you interested in doing? Thanks, Jeff From freyley at gmail.com Mon Sep 24 07:38:53 2007 From: freyley at gmail.com (Jeff Schwaber) Date: Sun, 23 Sep 2007 22:38:53 -0700 Subject: [portland] [Code Sprint] Project beginnings! Message-ID: <8db4a1910709232238p1d679733g183a94c6f8014d6a@mail.gmail.com> Hey all,[1] We had a pretty fabulous and successful first code sprint last Wednesday. Three projects were worked on: an agile planning tool, a dark or shadow or line-of-sight chess game, and something to do with talking to hardware that I wasn't terribly clear on. So...we're going to do it again. Wednesday, October 3rd, 7pm CubeSpace Come write some code with us. We're definitely going to do some Extreme Programming, and we had a Coding Dojo[2] of 3 around the dark chess. Do you have another method for learning and teaching coding? We can certainly try it. Everybody's welcome -- this is your chance for hybridization across language groups. Jeff [1] Yes, this message is has multiple list recipients. I'm half of the opinion that a code sprint list would be a good idea, half that it's ridiculous. [2] I've been thinking about adding a USB keyboard to the driver's seat of the Coding Dojo so that you can let the least experienced in the language/project/details write the code, then, when it's wrong, delete it and write the right code, delete it and let them write it again. Think of how martial arts are taught: the instructor does the move, the student follows, the instructor corrects, the student does it again. From afaulkner at mainzbradygroup.com Fri Sep 28 00:57:23 2007 From: afaulkner at mainzbradygroup.com (Allen Faulkner) Date: Thu, 27 Sep 2007 15:57:23 -0700 Subject: [portland] Python Contractor needed Message-ID: <20070928001514.DC6CE1E401D@bag.python.org> Our client is currently looking for a Sr. level Python developer to help them on a two - three month contract. They need the individual to have strong skills in Python, ZOPE, Apache and PostgresSQL. If you or anyone you know would be a good fit for this positions please send me a resume and give me a call at the number listed below. Allen D. Faulkner Sr. Staffing Specialist Mainz Brady Group 503-430-1706 direct 503-453-9850 mobile 503-961-8910 fax afaulkner at mainzbradygroup.com www.mainzbradygroup.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/portland/attachments/20070927/30c46950/attachment.htm From rshepard at appl-ecosys.com Fri Sep 28 20:15:01 2007 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 28 Sep 2007 11:15:01 -0700 (PDT) Subject: [portland] Using log() programmatically Message-ID: One of our applications uses wxPython as the UI. One of the widgets is a drop-down combo box list of scaling factors for variables. The choices in that widget are strings, which do not allow for mathematical computation. I've created a dictionary that associates numbers and log functions with the appropriate key strings: self.scaleDict = {'x 1': 1, 'x 10': 10, 'x 100': 100, 'x 1,000': 1000, 'x 10,000': 10000, 'x log 10': log(), 'x log 2': log(,2), 'x log e': log(e)} What I want to do is look up the selected key for that variable, then adjust a numeric value by multiplying, or taking the logarithm, by the value of the key. Doing this for the multipliers is easy enough, but I've no idea how to use the logs. On a related issue, I thought that I'd replace log2 and log(e) (the natural log) with numbers as values in the dictionary, but ipython keeps telling me that log() and log10() are not defined, even after importing math. Pointers much appreciated. Rich -- Richard B. Shepard, Ph.D. | The Environmental Permitting Applied Ecosystem Services, Inc. | Accelerators(TM) Voice: 503-667-4517 Fax: 503-667-8863 From robin at alldunn.com Fri Sep 28 20:47:58 2007 From: robin at alldunn.com (Robin Dunn) Date: Fri, 28 Sep 2007 11:47:58 -0700 Subject: [portland] Using log() programmatically In-Reply-To: References: Message-ID: <46FD4C5E.8070000@alldunn.com> Rich Shepard wrote: > One of our applications uses wxPython as the UI. One of the widgets is a > drop-down combo box list of scaling factors for variables. The choices in > that widget are strings, which do not allow for mathematical computation. > > I've created a dictionary that associates numbers and log functions with > the appropriate key strings: > > self.scaleDict = {'x 1': 1, 'x 10': 10, 'x 100': 100, 'x 1,000': 1000, > 'x 10,000': 10000, 'x log 10': log(), 'x log 2': log(,2), > 'x log e': log(e)} > > What I want to do is look up the selected key for that variable, then > adjust a numeric value by multiplying, or taking the logarithm, by the value > of the key. Doing this for the multipliers is easy enough, but I've no idea > how to use the logs. Instead of making the dictionary keys a value, you can make it be a function, something like this: def do_times1(val): return val def do_times10(val): return val * 10 ... def do_log10(val): return math.log(val) def do_log2(val): return math.log(val, 2) ... Then your dictionary would be defined something like this: self.scaleDict = {'x 1': do_times1, 'x 10': do_times10, ... 'x log 10': do_log10, 'x log 2': do_log2, ... } When you look up an item in the dictionary you'll get a reference to the function that you can call just a the same as if you had the original function name: func = self.scaleDict[key] newval = func(origval) -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! From adam at therobots.org Fri Sep 28 20:57:34 2007 From: adam at therobots.org (Adam Lowry) Date: Fri, 28 Sep 2007 11:57:34 -0700 Subject: [portland] Using log() programmatically In-Reply-To: <46FD4C5E.8070000@alldunn.com> References: <46FD4C5E.8070000@alldunn.com> Message-ID: <06F06EE2-4ACE-42B8-9E04-98CF20316903@therobots.org> On Sep 28, 2007, at 11:47 AM, Robin Dunn wrote: > Instead of making the dictionary keys a value, you can make it be a > function, something like this: > > def do_times1(val): > return val > I was just about to suggest something similar. I would probably use anonymous functions here - same effect, a little tighter code: self.scaleDict = { 'x 1': lambda x: x, 'x 10': lambda x: x * 10, ... 'x log 10': lambda x: math.log(x, 10), 'x log 2': lambda x: math.log(x, 2), 'x log e': lambda x: math.log(x), } self.scaleDict[key](x) Adam From rshepard at appl-ecosys.com Fri Sep 28 21:46:43 2007 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 28 Sep 2007 12:46:43 -0700 (PDT) Subject: [portland] Using log() programmatically In-Reply-To: <46FD4C5E.8070000@alldunn.com> References: <46FD4C5E.8070000@alldunn.com> Message-ID: On Fri, 28 Sep 2007, Robin Dunn wrote: > Instead of making the dictionary keys a value, you can make it be a > function, something like this: > > def do_times1(val): > return val > def do_times10(val): > return val * 10 > ... Thanks, Robin. I've seen this approach, but it didn't occur to me to use it. Rich -- Richard B. Shepard, Ph.D. | The Environmental Permitting Applied Ecosystem Services, Inc. | Accelerators(TM) Voice: 503-667-4517 Fax: 503-667-8863 From rshepard at appl-ecosys.com Fri Sep 28 21:49:06 2007 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 28 Sep 2007 12:49:06 -0700 (PDT) Subject: [portland] Using log() programmatically In-Reply-To: <06F06EE2-4ACE-42B8-9E04-98CF20316903@therobots.org> References: <46FD4C5E.8070000@alldunn.com> <06F06EE2-4ACE-42B8-9E04-98CF20316903@therobots.org> Message-ID: On Fri, 28 Sep 2007, Adam Lowry wrote: > I was just about to suggest something similar. I would probably use > anonymous functions here - same effect, a little tighter code: Thank you, Adam. I appreciate the insight. Rich -- Richard B. Shepard, Ph.D. | The Environmental Permitting Applied Ecosystem Services, Inc. | Accelerators(TM) Voice: 503-667-4517 Fax: 503-667-8863 From rshepard at appl-ecosys.com Sat Sep 29 03:04:43 2007 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 28 Sep 2007 18:04:43 -0700 (PDT) Subject: [portland] Indexing Lists of Tuples Message-ID: For some reason, I cannot find the answer to what I assumed to be a trivially simple question: given a list of tuples, how do I reference items within a given tuple? Looking at "Byte of Python," "Dive Into Python," and "Learning Python" the explanations of lists and tuples deal with the equivalent of a 1-dimensional array. The only reference to multiple indices, e.g., L[1][0], note that this is the fist element of the second item in the list. My experiments on my data bear this out. In my situation, I have rows retrieved from database tables and stored in variables as lists of tuples. For example: [(u'Low', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Decay S-Curve', 1, 0.0, 1.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0) (u'High', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Growth S-Curve', 2, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 1.0)] I would like to extract the tuple where element 5 == 2; in this example, the second tuple in the list. Is there a way to directly reference tuple 1, item 5 as one would in C as [1][5]? The best I've come up with is to search for the tuple with elements I want, then append them to a new list. Now I have a list with only one set of elements and I can index them directly. Spent too much time today beating my head against the wall, trying to learn how to address specific elements in lists of tuples. Can it be done? If so, please teach me how. TIA, Rich -- Richard B. Shepard, Ph.D. | The Environmental Permitting Applied Ecosystem Services, Inc. | Accelerators(TM) Voice: 503-667-4517 Fax: 503-667-8863 From hallettj at gmail.com Sat Sep 29 03:18:56 2007 From: hallettj at gmail.com (Jesse Hallett) Date: Fri, 28 Sep 2007 18:18:56 -0700 Subject: [portland] Indexing Lists of Tuples In-Reply-To: References: Message-ID: <8a02878f0709281818m11760b6fl15f59453f05febf2@mail.gmail.com> Rich, I just did some experimenting with your example. I was able to get at the element in question with L[1][5], just as you suggested. The only change I mad was to add a comma between the tuples that was probably left out when you pasted in the example. I'm using Python version 2.5.1, in case that makes any difference. Cheers, Jesse On 9/28/07, Rich Shepard wrote: > For some reason, I cannot find the answer to what I assumed to be a > trivially simple question: given a list of tuples, how do I reference items > within a given tuple? > > Looking at "Byte of Python," "Dive Into Python," and "Learning Python" the > explanations of lists and tuples deal with the equivalent of a 1-dimensional > array. The only reference to multiple indices, e.g., L[1][0], note that this > is the fist element of the second item in the list. My experiments on my > data bear this out. > > In my situation, I have rows retrieved from database tables and stored in > variables as lists of tuples. For example: > > [(u'Low', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Decay > S-Curve', 1, 0.0, 1.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0) > (u'High', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Growth > S-Curve', 2, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 1.0)] > > I would like to extract the tuple where element 5 == 2; in this example, > the second tuple in the list. Is there a way to directly reference tuple 1, item 5 > as one would in C as [1][5]? > > The best I've come up with is to search for the tuple with elements I > want, then append them to a new list. Now I have a list with only one set of > elements and I can index them directly. > > Spent too much time today beating my head against the wall, trying to > learn how to address specific elements in lists of tuples. Can it be done? > If so, please teach me how. > > TIA, > > Rich > > -- > Richard B. Shepard, Ph.D. | The Environmental Permitting > Applied Ecosystem Services, Inc. | Accelerators(TM) > Voice: 503-667-4517 Fax: 503-667-8863 > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From kirby.urner at gmail.com Sat Sep 29 03:20:16 2007 From: kirby.urner at gmail.com (kirby urner) Date: Fri, 28 Sep 2007 18:20:16 -0700 Subject: [portland] Indexing Lists of Tuples In-Reply-To: References: Message-ID: Helpful at all?: >>> thedata [(u'Low', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Decay S-Curve', 1, 0.0, 1.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0), (u'High', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Growth S-Curve', 2, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 1.0)] >>> [thetuple for thetuple in thedata if thetuple[4]==2] [] >>> [thetuple for thetuple in thedata if thetuple[5]==2] [(u'High', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Growth S-Curve', 2, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 1.0)] Kirby On 9/28/07, Rich Shepard wrote: > For some reason, I cannot find the answer to what I assumed to be a > trivially simple question: given a list of tuples, how do I reference items > within a given tuple? > > Looking at "Byte of Python," "Dive Into Python," and "Learning Python" the > explanations of lists and tuples deal with the equivalent of a 1-dimensional > array. The only reference to multiple indices, e.g., L[1][0], note that this > is the fist element of the second item in the list. My experiments on my > data bear this out. > > In my situation, I have rows retrieved from database tables and stored in > variables as lists of tuples. For example: > > [(u'Low', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Decay > S-Curve', 1, 0.0, 1.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0) > (u'High', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Growth > S-Curve', 2, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 1.0)] > > I would like to extract the tuple where element 5 == 2; in this example, > the second tuple in the list. Is there a way to directly reference tuple 1, item 5 > as one would in C as [1][5]? > > The best I've come up with is to search for the tuple with elements I > want, then append them to a new list. Now I have a list with only one set of > elements and I can index them directly. > > Spent too much time today beating my head against the wall, trying to > learn how to address specific elements in lists of tuples. Can it be done? > If so, please teach me how. > > TIA, > > Rich > > -- > Richard B. Shepard, Ph.D. | The Environmental Permitting > Applied Ecosystem Services, Inc. | Accelerators(TM) > Voice: 503-667-4517 Fax: 503-667-8863 > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From rshepard at appl-ecosys.com Sat Sep 29 03:27:24 2007 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 28 Sep 2007 18:27:24 -0700 (PDT) Subject: [portland] Indexing Lists of Tuples In-Reply-To: <8a02878f0709281818m11760b6fl15f59453f05febf2@mail.gmail.com> References: <8a02878f0709281818m11760b6fl15f59453f05febf2@mail.gmail.com> Message-ID: On Fri, 28 Sep 2007, Jesse Hallett wrote: > I just did some experimenting with your example. I was able to get at the > element in question with L[1][5], just as you suggested. The only change I > mad was to add a comma between the tuples that was probably left out when > you pasted in the example. Jesse, The comma wasn't left out by me; that example was cut-and-pasted from python output. It's apparently the way pysqlite2 writes lists of rows retrieved from SQLite3 tables. Perhaps I need to ask on the pysqlite mail list about this. Thanks, Rich -- Richard B. Shepard, Ph.D. | The Environmental Permitting Applied Ecosystem Services, Inc. | Accelerators(TM) Voice: 503-667-4517 Fax: 503-667-8863 From rshepard at appl-ecosys.com Sat Sep 29 03:34:21 2007 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 28 Sep 2007 18:34:21 -0700 (PDT) Subject: [portland] Indexing Lists of Tuples In-Reply-To: <8a02878f0709281818m11760b6fl15f59453f05febf2@mail.gmail.com> References: <8a02878f0709281818m11760b6fl15f59453f05febf2@mail.gmail.com> Message-ID: On Fri, 28 Sep 2007, Jesse Hallett wrote: > I just did some experimenting with your example. I was able to get at > the element in question with L[1][5], just as you suggested. The only > change I mad was to add a comma between the tuples that was probably > left out when you pasted in the example. Jesse, I was wrong in my reply. Here's another cut-and-paste from the python output, and there is a comma between the tuples. [(u'Low', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Decay S-Curve', 1, 0.0, 1.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0), (u'High', u'HabitatComplexity', u'Terrestrial', u'Wildlife', u'Growth S-Curve', 2, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 0.5, 1.0, 1.0)] Trying this interactively within ipython, it works for me, too. Now I'm really confused, because it's not working in my application! I must be doing something subtly different in there. It's a wxPython method in which I'm doing this. It works in ipython just fine, but not in the application. Sigh. Perhaps this weekend I'll take the time to play more with it. Apologies to everyone, Rich -- Richard B. Shepard, Ph.D. | The Environmental Permitting Applied Ecosystem Services, Inc. | Accelerators(TM) Voice: 503-667-4517 Fax: 503-667-8863