From jek at discorporate.us Fri Feb 8 02:42:46 2008 From: jek at discorporate.us (jason kirtland) Date: Thu, 07 Feb 2008 17:42:46 -0800 Subject: [portland] February Meeting: Tuesday, 2/12, 7pm @ CubeSpace Message-ID: <47ABB396.7000007@discorporate.us> Greetings all, Our February meeting is coming up next week. There are two talks planned: * virtualenv (Jason) Ever need a version of a library that's newer than the one installed on your system? Or older? Or need to deploy and maintain your software on any system without worrying about what's installed already? Or just want to try something out without hassling with permissions and installation? virtualenv is a clever little tool that brings sanity to Python development and deployment. * PySoy (Kirk) PySoy is a 3D game engine for Python. With the most computation-heavy parts of OpenGL and Physics processing in C, PySoy remains efficient while offering a high level object-oriented Python API. The goal is to allow for rapid development without sacrificing speed or flexibility. I'm not sure what Kirk has in mind for a demo, but it's certain to include way more exciting 3D goodness than virtualenv. We'll also have our usual small group discussions on the Pythonic topics of the day, including the upcoming PyCon convention in March. And we'll head over to the Side Door after. Hope to see you all there Tuesday! February 12, 2008 - 7pm CubeSpace 622 SE Grand Ave. Portland , OR 97214 503-206-3500 http://python.meetup.com/183/calendar/7070393/ From altis at semi-retired.com Fri Feb 8 06:50:29 2008 From: altis at semi-retired.com (Kevin Altis) Date: Thu, 7 Feb 2008 21:50:29 -0800 Subject: [portland] Fwd: Need an instructor References: Message-ID: Begin forwarded message: > From: Ward Cunningham > Date: February 7, 2008 7:16:53 AM PST > To: "David Squire" > Cc: "Squire, Carol" , Kevin Altis > > Subject: Re: Need an instructor > > Dave -- Kevin Altis is my contact with the Python community. > > Kevin -- Can you suggest someone for Dave, or a list on which he > might inquire? > > Best regards. -- Ward > > AboutUs > Ward Cunningham > 503-432-5682 > > On Feb 6, 2008, at 10:31 PM, David Squire wrote: > >> Ward, do you know anybody that might know Python? My wife, Carol, >> runs the open campus computer education program at >> PortlandCommunity College and she needs an instructor that has >> real world experience. >> >> Thanks, Dave >> >> From: Squire, Carol [mailto:csquire at ex.oci.pcc.edu] >> Sent: Wednesday, February 06, 2008 12:16 PM >> To: sjsquire at comcast.net; David Squire >> Subject: Need an instructor >> >> Hey, >> Do either of you know any programmers who use Python? We are in >> need of an instructor for a contract with Intel and can?t find >> anyone who knows it. I am hoping you might be able to ask your >> engineer friends if anyone is interested in teaching Python for us. >> Love, >> Carol > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/portland/attachments/20080207/1888f4b6/attachment.htm From rshepard at appl-ecosys.com Fri Feb 15 21:20:36 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Feb 2008 12:20:36 -0800 (PST) Subject: [portland] Iterating Through Tuples In A List Message-ID: I've not yet figured out the code that gives me what I need in this one method. I'm sure it's simple, but the proper approach eludes me. Data start with a list of tuples. I iterate through the list and extract each tuple using, for i in range(len(self.appData.tsets)): self.row = self.appData.tsets[i] For the sake of discussion, each tuple (self.row) contains a component, a subcomponent, the subcomponent's sequential number, and the total number of subcomponents in the component. So there are multiple tuples for each component. What I need to do is iterate through components. For each component, I want to call a plotting routine for the subcomponents, in sequential order, to the total number of subcomponents. The tuples are in the proper order. I've not succeeded in writing the code to do the above. If I print the components and the total number of subcomponents, for example, I get output like this: HabitatComplexity 2 HabitatComplexity 2 SpecialConcern 3 SpecialConcern 3 SpecialConcern 3 Variety 2 Variety 2 If I print the compnent, total of subcomponents, subcomponent sequential number, and subcomponent curve shape I get output like this: HabitatComplexity 2 1 Decay S-Curve HabitatComplexity 2 2 Growth S-Curve SpecialConcern 3 1 Decay S-Curve SpecialConcern 3 2 Bell Curve SpecialConcern 3 3 Growth S-Curve Variety 2 1 Decay S-Curve Variety 2 2 Growth S-Curve I need to call the plotting library for each component, for the maximum number of subcomponents, so that all subcomponents are plotted on the same set of axes. This is what I've not yet figured out how to do. Suggestions appreciated, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From jek at discorporate.us Fri Feb 15 21:43:36 2008 From: jek at discorporate.us (jason kirtland) Date: Fri, 15 Feb 2008 12:43:36 -0800 Subject: [portland] Iterating Through Tuples In A List In-Reply-To: References: Message-ID: <47B5F978.30305@discorporate.us> Rich Shepard wrote: > I've not yet figured out the code that gives me what I need in this one > method. I'm sure it's simple, but the proper approach eludes me. > > Data start with a list of tuples. I iterate through the list and extract > each tuple using, > > for i in range(len(self.appData.tsets)): > self.row = self.appData.tsets[i] > > For the sake of discussion, each tuple (self.row) contains a component, a > subcomponent, the subcomponent's sequential number, and the total number of > subcomponents in the component. So there are multiple tuples for each > component. > > What I need to do is iterate through components. For each component, I > want to call a plotting routine for the subcomponents, in sequential order, > to the total number of subcomponents. The tuples are in the proper order. > > I've not succeeded in writing the code to do the above. If I print the > components and the total number of subcomponents, for example, I get output > like this: > > HabitatComplexity 2 > HabitatComplexity 2 > SpecialConcern 3 > SpecialConcern 3 > SpecialConcern 3 > Variety 2 > Variety 2 > > If I print the compnent, total of subcomponents, subcomponent sequential > number, and subcomponent curve shape I get output like this: > > HabitatComplexity 2 1 Decay S-Curve > HabitatComplexity 2 2 Growth S-Curve > SpecialConcern 3 1 Decay S-Curve > SpecialConcern 3 2 Bell Curve > SpecialConcern 3 3 Growth S-Curve > Variety 2 1 Decay S-Curve > Variety 2 2 Growth S-Curve > > I need to call the plotting library for each component, for the maximum > number of subcomponents, so that all subcomponents are plotted on the same > set of axes. This is what I've not yet figured out how to do. > > Suggestions appreciated, the groupby function in itertools is one way: rows = [('HabitatComplexity',2,1,'Decay S-Curve'), ('HabitatComplexity',2,2,'Growth S-Curve'), ('SpecialConcern',3,1,'Decay S-Curve'), ('SpecialConcern',3,2,'Bell Curve'), ('SpecialConcern',3,3,'Growth S-Curve'), ('Variety',2,1,'Decay S-Curve'), ('Variety',2,2,'Growth S-Curve'),] from operator import itemgetter from itertools import groupby for component, grouped in groupby(rows, key=itemgetter(0)): print component for row in grouped: print "\t%s" % row[3] # this prints: # #HabitatComplexity # Decay S-Curve # Growth S-Curve #SpecialConcern # Decay S-Curve # Bell Curve # Growth S-Curve #Variety # Decay S-Curve # Growth S-Curve From dylanr at dylanreinhardt.com Fri Feb 15 21:40:47 2008 From: dylanr at dylanreinhardt.com (Dylan Reinhardt) Date: Fri, 15 Feb 2008 12:40:47 -0800 Subject: [portland] Iterating Through Tuples In A List In-Reply-To: References: Message-ID: <4c645a720802151240j29159cb7u3a03f2d691c4f001@mail.gmail.com> On 2/15/08, Rich Shepard wrote: > > Data start with a list of tuples. I iterate through the list and > extract > each tuple using, > > for i in range(len(self.appData.tsets)): > self.row = self.appData.tsets[i] Unless you *really* want to set self.row, I might do this instead: for row in self.appData.tsets: ... Beyond that, it's not exactly clear what the structure of your tuples is, but let's say you have the following: mytup = ( ('a', (1,2,3), 'b'), ('c', (5,6,7,8), 'c') ) The second element of each tuple is another tuple. One way you might manipulate this is: for row in mytup: print row[0] for inner in row[1]: print ' - ', inner That's pretty trivial, but it shows iterating over sub-collections of unequal length. Hopefully part of that answers your question. If that's not helpful, you might want to post a dump of a couple rows of the tuple you're struggling with. HTH, Dylan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/portland/attachments/20080215/de30672c/attachment.htm From dylanr at dylanreinhardt.com Fri Feb 15 21:53:01 2008 From: dylanr at dylanreinhardt.com (Dylan Reinhardt) Date: Fri, 15 Feb 2008 12:53:01 -0800 Subject: [portland] Iterating Through Tuples In A List In-Reply-To: <47B5F978.30305@discorporate.us> References: <47B5F978.30305@discorporate.us> Message-ID: <4c645a720802151253s3dda4e57x34380f021a33aa58@mail.gmail.com> On 2/15/08, jason kirtland wrote: > rows = [('HabitatComplexity',2,1,'Decay S-Curve'), > > ('HabitatComplexity',2,2,'Growth S-Curve'), > ('SpecialConcern',3,1,'Decay S-Curve'), > ('SpecialConcern',3,2,'Bell Curve'), > ('SpecialConcern',3,3,'Growth S-Curve'), > ('Variety',2,1,'Decay S-Curve'), > > ('Variety',2,2,'Growth S-Curve'),] Ah... that makes more sense. If that's what you have, you can also do this, if it helps: grouper = {} for row in rows: grouper.setdefault(row[0], []).append(row[3]) for comp in grouper.keys(): print comp for subcomp in grouper[comp]: print ' - ', subcomp FWIW, Dylan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/portland/attachments/20080215/4449fa3e/attachment.htm From rshepard at appl-ecosys.com Fri Feb 15 21:58:03 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Feb 2008 12:58:03 -0800 (PST) Subject: [portland] Iterating Through Tuples In A List In-Reply-To: <4c645a720802151240j29159cb7u3a03f2d691c4f001@mail.gmail.com> References: <4c645a720802151240j29159cb7u3a03f2d691c4f001@mail.gmail.com> Message-ID: On Fri, 15 Feb 2008, Dylan Reinhardt wrote: > Unless you *really* want to set self.row, I might do this instead: Dylan, Only because it's referenced from several functions within the module. > The second element of each tuple is another tuple. One way you might > manipulate this is: > > for row in mytup: > print row[0] > for inner in row[1]: > print ' - ', inner > > That's pretty trivial, but it shows iterating over sub-collections of > unequal length. Hopefully part of that answers your question. Ah! That I should have known. Let me work with this and put it into my context. Thanks, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From rshepard at appl-ecosys.com Fri Feb 15 22:00:22 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Feb 2008 13:00:22 -0800 (PST) Subject: [portland] Iterating Through Tuples In A List In-Reply-To: <47B5F978.30305@discorporate.us> References: <47B5F978.30305@discorporate.us> Message-ID: On Fri, 15 Feb 2008, jason kirtland wrote: > the groupby function in itertools is one way: > > rows = [('HabitatComplexity',2,1,'Decay S-Curve'), > ('HabitatComplexity',2,2,'Growth S-Curve'), > ('SpecialConcern',3,1,'Decay S-Curve'), > ('SpecialConcern',3,2,'Bell Curve'), > ('SpecialConcern',3,3,'Growth S-Curve'), > ('Variety',2,1,'Decay S-Curve'), > ('Variety',2,2,'Growth S-Curve'),] > from operator import itemgetter > from itertools import groupby > > for component, grouped in groupby(rows, key=itemgetter(0)): > print component > for row in grouped: > print "\t%s" % row[3] Jason, This looks more elegant and maintainable that what I was doing. I'll read about itertools and give this a try, too. Thank you, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From kirby.urner at gmail.com Fri Feb 15 23:54:11 2008 From: kirby.urner at gmail.com (kirby urner) Date: Fri, 15 Feb 2008 14:54:11 -0800 Subject: [portland] Iterating Through Tuples In A List In-Reply-To: References: Message-ID: On Feb 15, 2008 12:20 PM, Rich Shepard wrote: > I've not yet figured out the code that gives me what I need in this one > method. I'm sure it's simple, but the proper approach eludes me. > > Data start with a list of tuples. I iterate through the list and extract > each tuple using, > > for i in range(len(self.appData.tsets)): > self.row = self.appData.tsets[i] > Remember that you can go: for row in self.appData.tsets: print row i.e. it's not necessary to take the len of something simply to range through it by subscript. Way less subscripting goes on in Python as a result. > I've not succeeded in writing the code to do the above. If I print the > components and the total number of subcomponents, for example, I get output > like this: > > HabitatComplexity 2 > HabitatComplexity 2 > SpecialConcern 3 > SpecialConcern 3 > SpecialConcern 3 > Variety 2 > Variety 2 > > If I print the compnent, total of subcomponents, subcomponent sequential > number, and subcomponent curve shape I get output like this: > > HabitatComplexity 2 1 Decay S-Curve > HabitatComplexity 2 2 Growth S-Curve > SpecialConcern 3 1 Decay S-Curve > SpecialConcern 3 2 Bell Curve > SpecialConcern 3 3 Growth S-Curve > Variety 2 1 Decay S-Curve > Variety 2 2 Growth S-Curve > These look mutually consistent to me. Do you have input into what data structure to use? A dictionary might be better, e.g. {"HabitatComplexity":("Decay S-Curve", "Growth S-Curve"), "SpecialConcern":("Decay S-Curve", "Bell Curve", "Growth S-Curve"), "Variety":("Decay S-Curve", "Growth S-Curve")} Nevermind though. Sounds like you've got something more like: [("HabitatComplexity" 2, ("Decay S-Curve", "Growth S-Curve")), ("SpecialConcern", 3, ("Decay S-Curve", "Bell Curve", "Growth S-Curve")), ("Variety", 2, ("Decay S-Curve", "Growth S-Curve"))] Number of subcomponents is sort of "data sugar" as it'd be easy to just get it from len, but oh well. > I need to call the plotting library for each component, for the maximum > number of subcomponents, so that all subcomponents are plotted on the same > set of axes. This is what I've not yet figured out how to do. You could use your "Decay S-Curve" type strings (are they strings?) as pointers to plotting functions? Using the above data structure (list of tuples): >>> mydata = [("HabitatComplexity", 2, ("Decay S-Curve", "Growth S-Curve")), ("SpecialConcern", 3, ("Decay S-Curve", "Bell Curve", "Growth S-Curve")), ("Variety", 2, ("Decay S-Curve", "Growth S-Curve"))] >>> def f(x): return "Decay S-Curve" # pretend plot function >>> def g(x): return "Growth S-Curve" # pretend plot function >>> def b(x): return "Bell Curve" # pretend plot function >>> plots = {"Decay S-Curve": f, "Growth S-Curve": g, "Bell Curve": b} # pointers to functions >>> for row in mydata: subcomps = row[2] print row[0] for curve in subcomps: print "plotting: ", print plots[curve](1) # <--- (1) is "dummy data" -- the functions take arg x. HabitatComplexity plotting: Decay S-Curve plotting: Growth S-Curve SpecialConcern plotting: Decay S-Curve plotting: Bell Curve plotting: Growth S-Curve Variety plotting: Decay S-Curve plotting: Growth S-Curve > > Suggestions appreciated, > > Rich > Stay away from subscripts if at all possible. They're not as necessary in Python as in some other languages. Also, based on previous postings, I'm worried you don't really need "self" -- you're inside some class definition here? Kirby > -- > Richard B. Shepard, Ph.D. | Integrity Credibility > Applied Ecosystem Services, Inc. | Innovation > 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 Feb 16 00:17:58 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Feb 2008 15:17:58 -0800 (PST) Subject: [portland] Iterating Through Tuples In A List In-Reply-To: References: Message-ID: On Fri, 15 Feb 2008, kirby urner wrote: > Remember that you can go: > > for row in self.appData.tsets: > print row Thank you. > These look mutually consistent to me. Do you have input into what > data structure to use? A dictionary might be better, e.g. > > {"HabitatComplexity":("Decay S-Curve", "Growth S-Curve"), > "SpecialConcern":("Decay S-Curve", "Bell Curve", "Growth S-Curve"), > "Variety":("Decay S-Curve", "Growth S-Curve")} > > Nevermind though. Sounds like you've got something more like: > > [("HabitatComplexity" 2, ("Decay S-Curve", "Growth S-Curve")), > ("SpecialConcern", 3, ("Decay S-Curve", "Bell Curve", "Growth S-Curve")), > ("Variety", 2, ("Decay S-Curve", "Growth S-Curve"))] > > Number of subcomponents is sort of "data sugar" as it'd be easy > to just get it from len, but oh well. The examples are portions of each tuple. They're retrieved from database tables and each carries unique information. > You could use your "Decay S-Curve" type strings (are they strings?) > as pointers to plotting functions? That's exactly what I'm doing. Getting only the desired tuples to plot on the same axes has been my hangup. > Also, based on previous postings, I'm worried you don't really need "self" > -- you're inside some class definition here? Yes. And row is referenced in several functions. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From rshepard at appl-ecosys.com Sat Feb 16 00:21:02 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Feb 2008 15:21:02 -0800 (PST) Subject: [portland] Iterating Through Tuples In A List In-Reply-To: <47B5F978.30305@discorporate.us> References: <47B5F978.30305@discorporate.us> Message-ID: On Fri, 15 Feb 2008, jason kirtland wrote: > the groupby function in itertools is one way: The on-line library docs are quite terse. Has anyone written a python book (paper or on-line) that provides more details and commented examples of the itertools? I'd certainly understand better with more discussion of appropriate applications for each tool and multiple examples. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From mack at incise.org Sat Feb 16 09:00:21 2008 From: mack at incise.org (Nick Welch) Date: Sat, 16 Feb 2008 00:00:21 -0800 Subject: [portland] Iterating Through Tuples In A List In-Reply-To: <47B5F978.30305@discorporate.us> References: <47B5F978.30305@discorporate.us> Message-ID: <20080216080020.GC32159@incise.org> On Fri, Feb 15, 2008 at 12:43:36PM -0800, jason kirtland wrote: > the groupby function in itertools is one way: > from operator import itemgetter > from itertools import groupby > > for component, grouped in groupby(rows, key=itemgetter(0)): > print component > for row in grouped: > print "\t%s" % row[3] Dang, that's pretty sweet. I remember seeing itemgetter before, but groupby is a new discovery. pprint.pprint([ (component, map(itemgetter(3), grouped)) for component, grouped in groupby(rows, key=itemgetter(0)) ]) Functional programming that looks like a perverted SQL. The world needs more of this. -- Nick Welch | mack @ incise.org | http://incise.org From jek at discorporate.us Mon Feb 18 17:28:57 2008 From: jek at discorporate.us (jason kirtland) Date: Mon, 18 Feb 2008 08:28:57 -0800 Subject: [portland] Iterating Through Tuples In A List In-Reply-To: References: <47B5F978.30305@discorporate.us> Message-ID: <47B9B249.10909@discorporate.us> Rich Shepard wrote: > On Fri, 15 Feb 2008, jason kirtland wrote: > >> the groupby function in itertools is one way: > > The on-line library docs are quite terse. Has anyone written a python book > (paper or on-line) that provides more details and commented examples of the > itertools? I'd certainly understand better with more discussion of > appropriate applications for each tool and multiple examples. itertools was featured as Python Module of the Week a while back: http://www.doughellmann.com/projects/PyMOTW/ I haven't looked at the itertools one in particular but I've found other other PyMOTW features to be quite good. From rshepard at appl-ecosys.com Mon Feb 18 17:31:55 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 18 Feb 2008 08:31:55 -0800 (PST) Subject: [portland] Iterating Through Tuples In A List In-Reply-To: <47B9B249.10909@discorporate.us> References: <47B5F978.30305@discorporate.us> <47B9B249.10909@discorporate.us> Message-ID: On Mon, 18 Feb 2008, jason kirtland wrote: > itertools was featured as Python Module of the Week a while back: > > http://www.doughellmann.com/projects/PyMOTW/ > > I haven't looked at the itertools one in particular but I've found other > other PyMOTW features to be quite good. Thank you for the recommendation and pointer, Jason. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863