From freyley at gmail.com Thu Jan 3 01:37:58 2008 From: freyley at gmail.com (Jeff Schwaber) Date: Wed, 2 Jan 2008 16:37:58 -0800 Subject: [portland] Upcoming Meeting 1/8/2008 Message-ID: <8db4a1910801021637u4d47f661s5a0a424aacacc890@mail.gmail.com> Hey folks, It's 08, and we're meeting on the 8th. Who's got a numerological challenge for us? Over the last 6 months various people have talked about things. Have any of them changed your world? Did you give SQLAlchemy a whirl because of what Jason presented? Did you try Django because of Chris? You may not feel like this warrants a presentation, but I do. I'd like each one of you who tried out something that was presented on to stand up for 5 minutes and tell us how it went. Was it great? Did something seem easy now that you saw it? Was it actually really hard? There's no better way for us to build on our presentations than to hear how folks are using the software that we saw. And, of course, we also need people to talk so we can have a meeting. Anybody else want to chime in with a talk? What'd you do over the holidays and how pythonic was it? See you Tuesday.[1] Jeff [1] at Cubespace, at 7pm. From freyley at gmail.com Thu Jan 3 01:41:42 2008 From: freyley at gmail.com (Jeff Schwaber) Date: Wed, 2 Jan 2008 16:41:42 -0800 Subject: [portland] Code Sprint after the meeting Message-ID: <8db4a1910801021641l70d1d49fwb73fd0b01f698259@mail.gmail.com> And for a followup to our meeting announcement... Wednesday's the first 08 Code Sprint. We'll be getting back into things, so come join us at 7pm at CubeSpace. There's a website with more info: http://code.arlim.org/wiki Jeff From freyley at gmail.com Tue Jan 15 01:27:52 2008 From: freyley at gmail.com (Jeff Schwaber) Date: Mon, 14 Jan 2008 16:27:52 -0800 Subject: [portland] Saturday: more code sprinting Message-ID: <8db4a1910801141627s3f19ca1dhe086089070324e87@mail.gmail.com> Hey folks, Saturday, starting at 10am, there's going to be more code sprinting. But I've been invited to a competing event, a truffle hunt. Who's going to tell me about the fabulous project they have to work on, or their excitement and anticipation for this week's code sprint and keep me from going truffling instead? Jeff From rshepard at appl-ecosys.com Tue Jan 15 02:01:05 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 14 Jan 2008 17:01:05 -0800 (PST) Subject: [portland] Using Dictionary to Call Functions Message-ID: I've read in the Python Cookbook and various web sites the information on using a dictionary as a switch statement would be used in C. But, I've not seen -- or figured out -- how to call the keys correctly while passing arguments to the called function. Let me explain. The dictionary: curvePlot = { 'Decay S-Curve' : functions.zCurve(leftEdge, rightEdge), 'Bell Curve' : functions.gaussCurve(midpt, width), 'Growth S-Curve' : functions.sCurve(leftEdge, rightEdge), 'Beta' : functions.betaCurve(center, inflectPt, width), 'Data' : functions.dataCurve(ptList), 'Linear Increasing' : functions.linearIncrCurve(leftEdge, rightEdge), 'Linear Decreasing' : functions.linearDecrCurve(leftEdge, rightEdge), 'Left Shoulder' : functions.leftShoulderCurve(hiRight, loRight), 'Trapezoid' : functions.trapezoidCurve(loLeft, hiLeft, hiRight, loRight), 'Right Shoulder' : functions.rightShoulderCurve(loLeft, hiLeft, hiRight), 'Triangle' : functions.triangleCurve(loLeft, center, loRight), 'Singleton' : functions.singletonCurve(center, width), 'Rectangle' : functions.rectangleCurve(leftEdge, rightEdge), 'Outcome' : functions.outcomeCurve() } For each tuple in the list (from a database table) there is a value called 'shape.' This is the dictionary's key. The arguments are also values in each tuple, and they differ for each function call. I want to get the dictionary keys in sequential order (there may be 1 to 7), and call the appropriate function for each one. The functions use mathplotlib to draw the curves on a common set of axes. Suggestions and thoughts welcomed. 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 Tue Jan 15 02:32:45 2008 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 14 Jan 2008 17:32:45 -0800 Subject: [portland] Using Dictionary to Call Functions In-Reply-To: References: Message-ID: > I want to get the dictionary keys in sequential order (there may be 1 to > 7), and call the appropriate function for each one. The functions use > mathplotlib to draw the curves on a common set of axes. Hi Rich -- As the gurus here will tell you, dictionaries are by design ignorant of sequence, though using keys 1-7 makes it easy for a key press to access a function or whatever. A typical idiom in a 1970s style menu-driven program would be: myfuncs = [exit, foo, bar] while True: print """ ==== Main Menu 1 do foo 2 do bar 0 exit """ somenum = int( raw_input("Wanna do? ") ) # whatever error trapping if somenum == 0: break myfuncs[somenum]() # take action! (and loop to menu) That's very simplified and doesn't address your wanting to pass arguments etc. myfuncs = {0:exit, 1:foo, 2:bar} # dictionary instead of list would pretty much serve the same purpose. HTH, Kirby > > Suggestions and thoughts welcomed. > > Rich > > -- > 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 mccredie at gmail.com Tue Jan 15 02:59:11 2008 From: mccredie at gmail.com (Matt McCredie) Date: Mon, 14 Jan 2008 17:59:11 -0800 Subject: [portland] Using Dictionary to Call Functions In-Reply-To: <9e95df10801141758u579781d6v4326baad83cb25f@mail.gmail.com> References: <9e95df10801141758u579781d6v4326baad83cb25f@mail.gmail.com> Message-ID: <9e95df10801141759x2624b707u872ead8a8cf0e91@mail.gmail.com> > I've read in the Python Cookbook and various web sites the information on > using a dictionary as a switch statement would be used in C. But, I've not > seen -- or figured out -- how to call the keys correctly while passing > arguments to the called function. Let me explain. > > The dictionary: > > curvePlot = { > 'Decay S-Curve' : functions.zCurve(leftEdge, rightEdge), > 'Bell Curve' : functions.gaussCurve(midpt, width), > 'Growth S-Curve' : functions.sCurve(leftEdge, rightEdge), > 'Beta' : functions.betaCurve(center, inflectPt, width), > 'Data' : functions.dataCurve(ptList), > 'Linear Increasing' : functions.linearIncrCurve(leftEdge, rightEdge), > 'Linear Decreasing' : functions.linearDecrCurve(leftEdge, rightEdge), > 'Left Shoulder' : functions.leftShoulderCurve(hiRight, loRight), > 'Trapezoid' : functions.trapezoidCurve(loLeft, hiLeft, hiRight, loRight), > 'Right Shoulder' : functions.rightShoulderCurve(loLeft, hiLeft, hiRight), > 'Triangle' : functions.triangleCurve(loLeft, center, loRight), > 'Singleton' : functions.singletonCurve(center, width), > 'Rectangle' : functions.rectangleCurve(leftEdge, rightEdge), > 'Outcome' : functions.outcomeCurve() > } > > For each tuple in the list (from a database table) there is a value > called 'shape.' This is the dictionary's key. The arguments are also values > in each tuple, and they differ for each function call. > > I want to get the dictionary keys in sequential order (there may be 1 to > 7), and call the appropriate function for each one. The functions use > mathplotlib to draw the curves on a common set of axes. I'm a little confused about what you are trying to do. What it sounds like to me is that you have a list of tuples as follows: [ ('Decay S-Curve' ,leftEdge, rightEdge), ('Bell Curve', midpt, width), ('Growth S-Curve', leftEdge, rightEdge), ('Beta', inflectPt, width), ... ] Or maybe it looks more like this: [ ('Decay S-Curve' , (leftEdge, rightEdge)), ('Bell Curve', (midpt, width)), ('Growth S-Curve', (leftEdge, rightEdge)), ('Beta', (inflectPt, width)), ... ] And you want to call the functions that correspond to the shape names with the values from the database. lets assume the list of names and arguments is called funcs_to_call. Your code should look something like this: # Notice that I'm not actually calling the functions! curvePlot = { 'Decay S-Curve' : functions.zCurve 'Bell Curve' : functions.gaussCurve 'Growth S-Curve' : functions.sCurve 'Beta' : functions.betaCurve 'Data' : functions.dataCurve 'Linear Increasing' : functions.linearIncrCurve 'Linear Decreasing' : functions.linearDecrCurve 'Left Shoulder' : functions.leftShoulderCurve 'Trapezoid' : functions.trapezoidCurve 'Right Shoulder' : functions.rightShoulderCurve 'Triangle' : functions.triangleCurve 'Singleton' : functions.singletonCurve 'Rectangle' : functions.rectangleCurve 'Outcome' : functions.outcomeCurve } # assuming that funcs_to_call is in the first form: for shape_args in funcs_to_call: shape = shape_args[0] args = shape_args[1:] curvePlot[shape](*args) # assuming that funcs_to_call is in the second form: for shape, args in funcs_to_call: curvePlot[shape](*args) HTH, Matt From hallettj at gmail.com Wed Jan 16 00:40:57 2008 From: hallettj at gmail.com (Jesse Hallett) Date: Tue, 15 Jan 2008 15:40:57 -0800 Subject: [portland] Saturday: more code sprinting In-Reply-To: <8db4a1910801141627s3f19ca1dhe086089070324e87@mail.gmail.com> References: <8db4a1910801141627s3f19ca1dhe086089070324e87@mail.gmail.com> Message-ID: <8a02878f0801151540u4dc86dc8la903d67c6a8663ab@mail.gmail.com> Hi Jeff, I had an idea that I think would be fun as a group project. I have heard here and there about experiments involving creating computer programs that can reproduce and evolve. Sometimes this is done as part of a genetic algorithm; but sometimes it is just for fun. One story that really got me interested was told by a guy who created such a program in a Linux environment. He let it go for a while - but eventually got bored and wiped the directory containing the reproducing programs. Later he discovered that the programs had developed the ability the leave that directory, and so had actually escaped deletion. I am interested in finding out what other interesting behaviors might develop if these things are allowed to keep going for a while. Programs can be made to replicate and change by parsing their own source code into an abstract syntax tree. Then nodes are swapped out at random with nodes from another program, or that are randomly generated. The program then produces a new source file that incorporates the changes, compiles it, and sets it running. I would want to write this project in Scheme; mostly because parsing syntax trees in LISP derived languages is as easy as matching parenthesis. But any functional language would work. Functional languages are much better suited than languages from other paradigms because every node in a functional syntax tree is essentially a self-contained program. I think that the hardest part of this project will be answering these questions: 1. What sort of goals and challenges should be provided for these programs? 2. How will programs share genetic code and/or mutate so as to create interesting development? 3. How will programs interact? For instance, will they be able to eat each other? How will they exchange code? And how will the find each other for these purposes? After writing all of this, I found out that I won't be available on Saturday. So I think this is an idea to consider for a future code sprint. If anybody is interested, I recommend reading up on Scheme, or LISP generally, and genetic algorithms. But remember that this project differs from the usual implementation genetic algorithms in that reproduction would be unsupervised. Cheers, Jesse On Jan 14, 2008 4:27 PM, Jeff Schwaber wrote: > Hey folks, > > Saturday, starting at 10am, there's going to be more code sprinting. > > But I've been invited to a competing event, a truffle hunt. > > Who's going to tell me about the fabulous project they have to work > on, or their excitement and anticipation for this week's code sprint > and keep me from going truffling instead? > > Jeff > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From rshepard at appl-ecosys.com Wed Jan 16 20:38:45 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jan 2008 11:38:45 -0800 (PST) Subject: [portland] Please explain this error Message-ID: I need to identify every item belonging to another variable. Each item has a sequential number which is extracted from a database table and stored in the tuple called 'row'. Using this code fragment: for i in range(row[16]): idx = i+1 print row[1], '\t', idx the results include: Sedimentation 1 Sedimentation 2 Sedimentation 3 InfiltrationRate 1 InfiltrationRate 2 InfiltrationRate 3 Traceback (most recent call last): File "eikos.py", line 145, in OnProjParms projectReports().inputVals() File "/data1/eikos/reports.py", line 394, in inputVals for i in range(row[16]): TypeError: range() integer end argument expected, got unicode. Since the code _seems_ to work properly I don't understand why it doesn't end cleanly. I understand the words in the error message but not what I need to do to fix it. TIA, 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 Wed Jan 16 20:50:59 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Jan 2008 11:50:59 -0800 Subject: [portland] Please explain this error In-Reply-To: References: Message-ID: <478E6023.20607@discorporate.us> Rich Shepard wrote: > I need to identify every item belonging to another variable. Each item has > a sequential number which is extracted from a database table and stored in > the tuple called 'row'. Using this code fragment: > > for i in range(row[16]): > idx = i+1 > print row[1], '\t', idx > > the results include: > > Sedimentation 1 > Sedimentation 2 > Sedimentation 3 > InfiltrationRate 1 > InfiltrationRate 2 > InfiltrationRate 3 > Traceback (most recent call last): > File "eikos.py", line 145, in OnProjParms > projectReports().inputVals() > File "/data1/eikos/reports.py", line 394, in inputVals > for i in range(row[16]): > TypeError: range() integer end argument expected, got unicode. > > Since the code _seems_ to work properly I don't understand why it doesn't > end cleanly. I understand the words in the error message but not what I need > to do to fix it. looks like the value of row[16] is a unicode string, not a number. you could check it via assert isinstance(row[16], int) for i in range(row[16]): ... and/or workaround it by converting to an integer: for i in range(int(row[16])): ... From jek at discorporate.us Wed Jan 16 22:05:47 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Jan 2008 13:05:47 -0800 Subject: [portland] Please explain this error In-Reply-To: References: <478E5FEA.9020809@discorporate.us> Message-ID: <478E71AB.2080701@discorporate.us> Rich Shepard wrote: > On Wed, 16 Jan 2008, jason kirtland wrote: > >> looks like the value of row[16] is a unicode string, not a number. you >> could check it via > > ... >> and/or workaround it by converting to an integer: >> >> for i in range(int(row[16])): > > Jason, > > That's what I thought, too, but when I had tried the above I get: > > Traceback (most recent call last): > File "eikos.py", line 145, in OnProjParms > projectReports().inputVals() > File "/data1/eikos/reports.py", line 394, in inputVals > for i in range(int(row[16])): > ValueError: invalid literal for int(): > > That's why I'm having difficulty discerning where the error originates. What's the repr() of row[16] at that point? I'll guess that it's the empty string: u'', coming from the database row. Perhaps something is storing '' where it means to be storing NULL. From rshepard at appl-ecosys.com Wed Jan 16 23:26:24 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jan 2008 14:26:24 -0800 (PST) Subject: [portland] Clue Stick Needed Message-ID: I am embarrassed to have to ask for help on this issue, but I'm just not seeing how to accomplish the task. Selected from a database table is a list of tuples; each tuple I call a 'row' of category names. Each name has from 1 to 7 subunits, and its sequential number is in row[5]. The total number of subunits is row[16]. Both row[5] and row[16] are integers. What I need to do is go through the list of rows and isolate the items, in sequential order, grouped by names. In C I would write 'for i=0, i Voice: 503-667-4517 Fax: 503-667-8863 From rshepard at appl-ecosys.com Thu Jan 17 00:54:02 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jan 2008 15:54:02 -0800 (PST) Subject: [portland] Clue Stick Needed In-Reply-To: References: Message-ID: On Wed, 16 Jan 2008, Rich Shepard wrote: > What I need to do is go through the list of rows and isolate the items, > in sequential order, grouped by names. In C I would write 'for i=0, > i < row[16]', is not valid. If I try a nested while loop, it hangs on the > first item of the first variable. I think that I'm making progress, but I'm still not there. Here's the relevant portion of the function: proper = lambda t: (t[3],t[2], t[1], t[0], t[5]) sorted(self.appData.tsets, key=proper) for i in range(len(self.appData.tsets)): row = self.appData.tsets[i] # select component, subcomponent, variable names curComp = row[3] curSub = row[2] curVar = row[1] tb.textOut(row[3]) tb.x += 9 if row[2] == '': tb.x += 36 tb.textOut(curSub) tb.x += 9 tb.textLine(curVar) for i in range(7): if i == row[16]: print curVar, row[0], row[5], row[4] This throws no errors, but the resulting list is still not in order: FloodControl Poor 1 Left Shoulder FloodControl Average 2 Trapezoid AnimalRefugia Poor 1 Left Shoulder AnimalRefugia High 3 Right Shoulder FloodControl High 3 Right Shoulder AnimalRefugia Adequate 2 Trapezoid The third FloodControl should follow the second one. Is my syntax error obvious? 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 Thu Jan 17 01:01:07 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Jan 2008 16:01:07 -0800 Subject: [portland] Clue Stick Needed In-Reply-To: References: Message-ID: <478E9AC3.6030706@discorporate.us> Rich Shepard wrote: > I think that I'm making progress, but I'm still not there. Here's the > relevant portion of the function: > > proper = lambda t: (t[3],t[2], t[1], t[0], t[5]) > sorted(self.appData.tsets, key=proper) > for i in range(len(self.appData.tsets)): > row = self.appData.tsets[i] > # select component, subcomponent, variable names > curComp = row[3] > curSub = row[2] > curVar = row[1] > tb.textOut(row[3]) > tb.x += 9 > if row[2] == '': > tb.x += 36 > tb.textOut(curSub) > tb.x += 9 > tb.textLine(curVar) > for i in range(7): > if i == row[16]: > print curVar, row[0], row[5], row[4] > > This throws no errors, but the resulting list is still not in order: > > FloodControl Poor 1 Left Shoulder > FloodControl Average 2 Trapezoid > AnimalRefugia Poor 1 Left Shoulder > AnimalRefugia High 3 Right Shoulder > FloodControl High 3 Right Shoulder > AnimalRefugia Adequate 2 Trapezoid > > The third FloodControl should follow the second one. Is my syntax error > obvious? It's here: > proper = lambda t: (t[3],t[2], t[1], t[0], t[5]) > sorted(self.appData.tsets, key=proper) > for i in range(len(self.appData.tsets)): sorted() is sorting a copy of the tsets and discarding the result. Either: self.appData.tsets.sort(key=proper) if tsets is a list and you don't mind modifying in-place, or, better: for i, row in enumerate(sorted(self.appData.tsets, key=proper)): # select component, subcomponent, variable names curComp = row[3] From rshepard at appl-ecosys.com Thu Jan 17 01:31:22 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jan 2008 16:31:22 -0800 (PST) Subject: [portland] Clue Stick Needed In-Reply-To: <478E9AC3.6030706@discorporate.us> References: <478E9AC3.6030706@discorporate.us> Message-ID: On Wed, 16 Jan 2008, jason kirtland wrote: > It's here: > > proper = lambda t: (t[3],t[2], t[1], t[0], t[5]) > > sorted(self.appData.tsets, key=proper) > > for i in range(len(self.appData.tsets)): > > sorted() is sorting a copy of the tsets and discarding the result. Either: > > self.appData.tsets.sort(key=proper) > > if tsets is a list and you don't mind modifying in-place, or, better: Jason, A-ha! I didn't catch that. I don't mind sorting the list in place. And, I'll use a different loop index in the second 'for' loop. 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 Thu Jan 17 01:56:41 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jan 2008 16:56:41 -0800 (PST) Subject: [portland] Clue Stick Needed -- RESOLVED In-Reply-To: <478E9AC3.6030706@discorporate.us> References: <478E9AC3.6030706@discorporate.us> Message-ID: On Wed, 16 Jan 2008, jason kirtland wrote: > self.appData.tsets.sort(key=proper) Jason/Dylan: This solves several potential problems because rows are not kept in any particular order in a database table, so ordering them makes it much easier to get the results we need. Many thanks, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From dylanr at dylanreinhardt.com Thu Jan 17 01:03:24 2008 From: dylanr at dylanreinhardt.com (Dylan Reinhardt) Date: Wed, 16 Jan 2008 16:03:24 -0800 Subject: [portland] Clue Stick Needed In-Reply-To: References: Message-ID: <4c645a720801161603r397635fas7f4576b1227226e6@mail.gmail.com> You're using the variable "i" in two different loops here. That's probably not going to do what you intend. In any event, you're probably better off iterating through items in a collection rather than iterating over the index of a size. Ex: for row in dataset: foo = row[3] rather than for i in range(len(dataset)): foo = dataset[i][3] HTH, Dylan On 1/16/08, Rich Shepard wrote: > > On Wed, 16 Jan 2008, Rich Shepard wrote: > > > What I need to do is go through the list of rows and isolate the > items, > > in sequential order, grouped by names. In C I would write 'for i=0, > > i i > > < row[16]', is not valid. If I try a nested while loop, it hangs on the > > first item of the first variable. > > I think that I'm making progress, but I'm still not there. Here's the > relevant portion of the function: > > proper = lambda t: (t[3],t[2], t[1], t[0], t[5]) > sorted(self.appData.tsets, key=proper) > for i in range(len(self.appData.tsets)): > row = self.appData.tsets[i] > # select component, subcomponent, variable names > curComp = row[3] > curSub = row[2] > curVar = row[1] > tb.textOut(row[3]) > tb.x += 9 > if row[2] == '': > tb.x += 36 > tb.textOut(curSub) > tb.x += 9 > tb.textLine(curVar) > for i in range(7): > if i == row[16]: > print curVar, row[0], row[5], row[4] > > This throws no errors, but the resulting list is still not in order: > > FloodControl Poor 1 Left Shoulder > FloodControl Average 2 Trapezoid > AnimalRefugia Poor 1 Left Shoulder > AnimalRefugia High 3 Right Shoulder > FloodControl High 3 Right Shoulder > AnimalRefugia Adequate 2 Trapezoid > > The third FloodControl should follow the second one. Is my syntax error > obvious? > > Rich > > > > > > -- > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/portland/attachments/20080116/5fbcf168/attachment.htm From rshepard at appl-ecosys.com Fri Jan 18 01:16:46 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Jan 2008 16:16:46 -0800 (PST) Subject: [portland] Dictionary As Switch Statement Message-ID: I want to use a dictionary to select the appropriate function to call based on the key value. However, I'm missing something simple here as I try to implement it. The dictionary: curvePlot = { 'Decay S-Curve' : zCurve(self), 'Bell Curve' : bellCurve(self), 'Growth S-Curve' : sCurve(self), 'Beta' : betaCurve(self), 'Data' : dataCurve(self), 'Linear Increasing' : linIncrCurve(self), 'Linear Decreasing' : linDecrCurve(self), 'Left Shoulder' : leftShouldCurve(self), 'Trapezoid' : trapCurve(self), 'Right Shoulder' : rightShouldCurve(self), 'Triangle' : triangCurve(self), 'Singleton' : singleCurve(self), 'Rectangle' : rectCurve(self), 'Outcome' : resultsCurve(self) } I can print out the keys, in a different order; 'print curvePlot.keys()' yields: ['Left Shoulder', 'Singleton', 'Outcome', 'Bell Curve', 'Right Shoulder', 'Growth S-Curve', 'Beta', 'Linear Increasing', 'Decay S-Curve', 'Linear Decreasing', 'Trapezoid', 'Triangle', 'Data', 'Rectangle'] But, when I try to print the entire dictionary, the values are not shown; 'print curvePlot' produces: {'Left Shoulder': None, 'Singleton': None, 'Outcome': None, 'Bell Curve': None, 'Right Shoulder': None, 'Growth S-Curve': None, 'Beta': None, 'Linear Increasing': None, 'Decay S-Curve': None, 'Linear Decreasing': None, 'Trapezoid': None, 'Triangle': None, 'Data': None, 'Rectangle': None} What have I done incorrectly that I cannot produce the value for a given key? When I pass the value of the key (it's the fifth item in a tuple so it's addressed as 'row[4]') all I get is 'None.' 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 Jan 18 01:48:24 2008 From: kirby.urner at gmail.com (kirby urner) Date: Thu, 17 Jan 2008 16:48:24 -0800 Subject: [portland] Dictionary As Switch Statement In-Reply-To: References: Message-ID: > > What have I done incorrectly that I cannot produce the value for a given > key? When I pass the value of the key (it's the fifth item in a tuple so > it's addressed as 'row[4]') all I get is 'None.' > > Rich > Hey Rich -- Dictionaries very much don't care about order, i.e. those keys are defined *not* to come in first, second, third place etc. plus forget about 'alphabetical'. Imagine curvePlot.keys() listing the keys in a different order each time, and realize why in Python we're happy with that outcome. The only way to grab a single value that's not idiosyncratic is to reach in with a key, a string in your example e.g.: curvePlot[ 'Decay S-Curve' ] should return zCurve(self) but then I'm suspicious of why you have "self" mentioned, as that's normally not passed as an argument. Are your functions or objects returning None then? Note: curvePlot[0] is by definition meaningless (if you want sequential access, don't use a dictionary, use a list or tuple). Kirby On Jan 17, 2008 4:16 PM, Rich Shepard wrote: > I want to use a dictionary to select the appropriate function to call > based on the key value. However, I'm missing something simple here as I try > to implement it. > > The dictionary: > > curvePlot = { > 'Decay S-Curve' : zCurve(self), > 'Bell Curve' : bellCurve(self), > 'Growth S-Curve' : sCurve(self), > 'Beta' : betaCurve(self), > 'Data' : dataCurve(self), > 'Linear Increasing' : linIncrCurve(self), > 'Linear Decreasing' : linDecrCurve(self), > 'Left Shoulder' : leftShouldCurve(self), > 'Trapezoid' : trapCurve(self), > 'Right Shoulder' : rightShouldCurve(self), > 'Triangle' : triangCurve(self), > 'Singleton' : singleCurve(self), > 'Rectangle' : rectCurve(self), > 'Outcome' : resultsCurve(self) > } > > I can print out the keys, in a different order; 'print curvePlot.keys()' > yields: > > ['Left Shoulder', 'Singleton', 'Outcome', 'Bell Curve', 'Right > Shoulder', 'Growth S-Curve', 'Beta', 'Linear Increasing', 'Decay S-Curve', > 'Linear Decreasing', 'Trapezoid', 'Triangle', 'Data', 'Rectangle'] > > But, when I try to print the entire dictionary, the values are not shown; > 'print curvePlot' produces: > > {'Left Shoulder': None, 'Singleton': None, 'Outcome': None, 'Bell Curve': > None, 'Right Shoulder': None, 'Growth S-Curve': None, 'Beta': None, 'Linear > Increasing': None, 'Decay S-Curve': None, 'Linear Decreasing': None, > 'Trapezoid': None, 'Triangle': None, 'Data': None, 'Rectangle': None} > -- > 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 Fri Jan 18 02:18:28 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Jan 2008 17:18:28 -0800 (PST) Subject: [portland] Dictionary As Switch Statement In-Reply-To: References: Message-ID: On Thu, 17 Jan 2008, kirby urner wrote: > Dictionaries very much don't care about order, Kirby, That's what I thought when I saw the changed order. Similar to database table rows not necessarily being in the same sequence. > The only way to grab a single value that's not idiosyncratic is > to reach in with a key, a string in your example e.g.: > > curvePlot[ 'Decay S-Curve' ] When I did this and saw None as a result I started looking for the reason why. > should return zCurve(self) but then I'm suspicious of why you > have "self" mentioned, as that's normally not passed as an > argument. Are your functions or objects returning None then? I use 'self' because I thought that the function calls needed the trailing parentheses to identify them as functions. When I did this, python told me it was expecting 1 argument for each function and I supplied 0 arguments. So I added 'self' and the incorrect argument number error went away. 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 Jan 18 02:41:31 2008 From: kirby.urner at gmail.com (kirby urner) Date: Thu, 17 Jan 2008 17:41:31 -0800 Subject: [portland] Dictionary As Switch Statement In-Reply-To: References: Message-ID: > I use 'self' because I thought that the function calls needed the trailing > parentheses to identify them as functions. When I did this, python told me > it was expecting 1 argument for each function and I supplied 0 arguments. So > I added 'self' and the incorrect argument number error went away. > > Thank you, > > Rich Actually, they don't require the parentheses except to trigger them as "callables" (a Pythonic jargon word, "iterables" being another favorite -- dictionaries and lists are both iterables, as are generator expressions). So for example, you can go: def f(x): return x * x # arbitrary function, takes x def g(x): return x + 2 # another function then: myfuncs = {'square it' : f, 'add 2' : g} # a dictionary, no parentheses Then if the user chooses "square it" for some reason you can go: x = 10 myfuncs["square it"](x) where x is getting its value from somewhere in scope. Note that myfuncs["square it"] is merely returning the function object f, whereas the parentheses and argument are here being supplied at runtime. 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 Fri Jan 18 03:28:27 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Jan 2008 18:28:27 -0800 (PST) Subject: [portland] Dictionary As Switch Statement In-Reply-To: References: Message-ID: On Thu, 17 Jan 2008, kirby urner wrote: > Actually, they don't require the parentheses except to trigger them as > "callables" (a Pythonic jargon word, "iterables" being another favorite -- > dictionaries and lists are both iterables, as are generator expressions). Thank you, Kirby. That clarifies the situation. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From kirklin.mcdonald at gmail.com Fri Jan 18 22:23:00 2008 From: kirklin.mcdonald at gmail.com (Kirk McDonald) Date: Fri, 18 Jan 2008 13:23:00 -0800 Subject: [portland] Fwd: Dictionary As Switch Statement In-Reply-To: <25bd58d10801171647v4d770d33s660a81244bd656b7@mail.gmail.com> References: <25bd58d10801171647v4d770d33s660a81244bd656b7@mail.gmail.com> Message-ID: <25bd58d10801181323n63545247l964b462fc2700869@mail.gmail.com> Okay, here's that message again. ---------- Forwarded message ---------- From: Kirk McDonald Date: Jan 17, 2008 4:47 PM Subject: Re: [portland] Dictionary As Switch Statement To: Rich Shepard On Jan 17, 2008 4:16 PM, Rich Shepard wrote: > I want to use a dictionary to select the appropriate function to call > based on the key value. However, I'm missing something simple here as I try > to implement it. > > The dictionary: > > curvePlot = { > 'Decay S-Curve' : zCurve(self), > 'Bell Curve' : bellCurve(self), > 'Growth S-Curve' : sCurve(self), > 'Beta' : betaCurve(self), > 'Data' : dataCurve(self), > 'Linear Increasing' : linIncrCurve(self), > 'Linear Decreasing' : linDecrCurve(self), > 'Left Shoulder' : leftShouldCurve(self), > 'Trapezoid' : trapCurve(self), > 'Right Shoulder' : rightShouldCurve(self), > 'Triangle' : triangCurve(self), > 'Singleton' : singleCurve(self), > 'Rectangle' : rectCurve(self), > 'Outcome' : resultsCurve(self) > } > > I can print out the keys, in a different order; 'print curvePlot.keys()' > yields: > > ['Left Shoulder', 'Singleton', 'Outcome', 'Bell Curve', 'Right > Shoulder', 'Growth S-Curve', 'Beta', 'Linear Increasing', 'Decay S-Curve', > 'Linear Decreasing', 'Trapezoid', 'Triangle', 'Data', 'Rectangle'] > > But, when I try to print the entire dictionary, the values are not shown; > 'print curvePlot' produces: > > {'Left Shoulder': None, 'Singleton': None, 'Outcome': None, 'Bell Curve': > None, 'Right Shoulder': None, 'Growth S-Curve': None, 'Beta': None, 'Linear > Increasing': None, 'Decay S-Curve': None, 'Linear Decreasing': None, > 'Trapezoid': None, 'Triangle': None, 'Data': None, 'Rectangle': None} > > What have I done incorrectly that I cannot produce the value for a given > key? When I pass the value of the key (it's the fifth item in a tuple so > it's addressed as 'row[4]') all I get is 'None.' > > Rich > The values in the dictionary should be the function objects themselves. For example: def f(x): print x*2 def g(x): print x*10 switch = { 'f': f, 'g': g, } You should only call the function after you index the dictionary: switch['f'](10) # prints 20 This implies that all of the callables in the dictionary must have compatible parameters. From jek at discorporate.us Sat Jan 19 00:38:14 2008 From: jek at discorporate.us (jason kirtland) Date: Fri, 18 Jan 2008 15:38:14 -0800 Subject: [portland] list administrivia Message-ID: <47913866.2020704@discorporate.us> Hi all, The list policy of 'replies go to sender' seemed to have a detrimental effect on the last couple of threads. As an experiment, I've tweaked mailman to send replies back to the list by default. Let's give that a try for a bit, and if it doesn't work out we can revert. Cheers, Jason From rshepard at appl-ecosys.com Sat Jan 19 00:54:12 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 18 Jan 2008 15:54:12 -0800 (PST) Subject: [portland] list administrivia In-Reply-To: <47913866.2020704@discorporate.us> References: <47913866.2020704@discorporate.us> Message-ID: On Fri, 18 Jan 2008, jason kirtland wrote: > The list policy of 'replies go to sender' seemed to have a detrimental > effect on the last couple of threads. As an experiment, I've tweaked > mailman to send replies back to the list by default. Let's give that a try > for a bit, and if it doesn't work out we can revert. Jason, When I've replied to a thread I've initiated I see both the individual and the list in the To: field. I always remove the individual's address and post to the list because none of us needs two copies of messages. This behavior may be more due to my use of pine than to the way the MLM is configured, but I've not noticed a problem. 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 Wed Jan 30 00:23:20 2008 From: jek at discorporate.us (jason kirtland) Date: Tue, 29 Jan 2008 15:23:20 -0800 Subject: [portland] PyCon 2008: Chicago, March Message-ID: <479FB568.5080507@discorporate.us> Registration recently opened for PyCon 2008. This year's conference is in Chicago and has a great line-up of sessions running from March 14-16: http://us.pycon.org/2008/conference/ ...including "Your Pythonic Math Class of the Future" by fellow group member Kirby Urner. There is also a tutorial day on March 13th with some great tutorials: http://us.pycon.org/2008/tutorials/schedule/ And four days of development sprints running from March 17-20, including work on Python itself, Django, TurboGears, Pylons, Jython, Trac... http://us.pycon.org/2008/sprints/projects/ And lots more... http://us.pycon.org Early-bird registration rates ($400 corporate, $220 hobbyist, $125 student) are available through February 20. Rooms in the conference hotel are $99/night, sharing encouraged. There is also financial aid available through the Python Software Foundation. If you're thinking of going and are interested in sharing a room to reduce costs, post to the list or privately to me if you prefer and I'll try to act as local matchmaker. I'm looking for roomies, myself. Airfare to Chicago was pretty still pretty reasonable last I looked, and so is Amtrak... 48-hour train hackfest, anyone? :) Cheers, Jason From kaplanw at gmail.com Wed Jan 30 06:14:06 2008 From: kaplanw at gmail.com (Will Kaplan) Date: Tue, 29 Jan 2008 21:14:06 -0800 Subject: [portland] Python Contractor request Message-ID: <6654b2c90801292114x580ecd6fm730482d0a0d94a42@mail.gmail.com> Greetings all- Posting to request information regarding Python Developers. My employer, a Portland area financial services firm, is seeking a contract python developer (or firm) for a client reporting module for our website. Strong Python and MySQL skills are a must. Knowledge of Django would be a plus. If you, or someone you know, might be interested please email me at kaplanw (at) gmail.com Thank you kindly, Will Kaplan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/portland/attachments/20080129/065ef938/attachment.htm