From kirby.urner at gmail.com Tue Apr 1 16:11:09 2008 From: kirby.urner at gmail.com (kirby urner) Date: Tue, 1 Apr 2008 07:11:09 -0700 Subject: [portland] Pycon 2008 #53 on Google Video In-Reply-To: <47F14A3A.4010304@discorporate.us> References: <47F14A3A.4010304@discorporate.us> Message-ID: > Great talk! For some reason my workstation didn't like the Google > video, but the talk popped up in the PyCon2008 YouTube feed today and I > watched it there: Thanks Jason. Also watched the reinteract demo. Made me want to play with matplotlib more too -- not sure how much it's the plots that grabbed me, versus the "go back in time" way of re-editing, vs. "copying down" as in IDLE, pyShell set. > I watched the screencast and it seems pretty neat, especially for math. > A little Reinteract show and tell would make a nice addition to the > lineup for the April meeting, if someone wanted to... ;-) > > -j My focus is Unicode these days -- just finished an I Ching demo in Python 3, tosses coins, prints in Chinese (plus the hexagrams themselves are in the Unicode code space). Still not sure about how print( ) works, e.g. two hexagrams in a tuple prints with unicodes spelled out, whereas printing each hexagram individually as in tuple[0], tuple[1], prints the correct glyph (horizontal and broken lines). Kirby From rshepard at appl-ecosys.com Tue Apr 1 19:10:45 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Apr 2008 10:10:45 -0700 (PDT) Subject: [portland] A List of Object Instances? Message-ID: I've discovered that I cannot assemble a list of graph curve data so that multiple curves can be plotted on the same axes. The issue appears to be that instances of the pyx.graph.graph.graphxy objects are created, not strings or integers. Is there a Python data structure that can hold several of these object instances so they can be passed to the plotting function? 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 Apr 1 19:33:40 2008 From: kirby.urner at gmail.com (kirby urner) Date: Tue, 1 Apr 2008 10:33:40 -0700 Subject: [portland] A List of Object Instances? In-Reply-To: References: Message-ID: Hi Rich -- I see docs about plotting multiple data sets at the pyx web site: http://pyx.sourceforge.net/examples/graphs/change.html Was this stuff not useful? You can put objects in lists or tuples just like any other object (everything is an object in Python), but I think further help on this plotting problem will be too generic minus specific familiarity with pyx. Dunno if anyone here uses (I've never). Kirby On Tue, Apr 1, 2008 at 10:10 AM, Rich Shepard wrote: > I've discovered that I cannot assemble a list of graph curve data so that > multiple curves can be plotted on the same axes. The issue appears to be > that instances of the pyx.graph.graph.graphxy objects are created, not > strings or integers. > > Is there a Python data structure that can hold several of these object > instances so they can be passed to the plotting function? > > 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 rshepard at appl-ecosys.com Tue Apr 1 19:54:16 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Apr 2008 10:54:16 -0700 (PDT) Subject: [portland] A List of Object Instances? In-Reply-To: References: Message-ID: On Tue, 1 Apr 2008, kirby urner wrote: > I see docs about plotting multiple data sets at the pyx web site: > Was this stuff not useful? Kirby, Only to the extent that it showed all graph.data instances need to be presented before the styles. Examples are always the simplest cases. I cannot write the script the way the example does because the curves to be plotted vary. > You can put objects in lists or tuples just like any other object > (everything is an object in Python), but I think further help on this > plotting problem will be too generic minus specific familiarity > with pyx. Dunno if anyone here uses (I've never). Well I posted a message on that list, too. It's good to know that objects can be list items. Perhaps I'm not appending them properly. I get no errors when running the test code, but only the last curve is plotted. 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 Tue Apr 1 20:09:28 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Apr 2008 11:09:28 -0700 (PDT) Subject: [portland] A List of Object Instances? -- SOLVED In-Reply-To: References: Message-ID: On Tue, 1 Apr 2008, Rich Shepard wrote: > Well I posted a message on that list, too. It's good to know that > objects can be list items. Perhaps I'm not appending them properly. I get > no errors when running the test code, but only the last curve is plotted. Solved the problem. I created the list within a for loop so it was cleared each time through. D'oh! Moving the creation above the loop fixed the problem. 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 Tue Apr 1 20:10:50 2008 From: dylanr at dylanreinhardt.com (Dylan Reinhardt) Date: Tue, 1 Apr 2008 11:10:50 -0700 Subject: [portland] A List of Object Instances? In-Reply-To: References: Message-ID: <4c645a720804011110u5979818fk76d51850f727ce8b@mail.gmail.com> On Tue, Apr 1, 2008 at 10:10 AM, Rich Shepard wrote: > Is there a Python data structure that can hold several of these object > instances so they can be passed to the plotting function? > There are limits to what you can use as a dictionary key, but no limits (that I know of) as to what kind of object you can put in a list. Perhaps your problem has something to do with the way your list elements are being appended and/or accessed? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/portland/attachments/20080401/107f4ef3/attachment.htm From rshepard at appl-ecosys.com Tue Apr 1 20:17:31 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Apr 2008 11:17:31 -0700 (PDT) Subject: [portland] A List of Object Instances? In-Reply-To: <4c645a720804011110u5979818fk76d51850f727ce8b@mail.gmail.com> References: <4c645a720804011110u5979818fk76d51850f727ce8b@mail.gmail.com> Message-ID: On Tue, 1 Apr 2008, Dylan Reinhardt wrote: > Perhaps your problem has something to do with the way your list elements > are being appended and/or accessed? Dylan, Our messages crossed on their ways to the mail list. Yes, I was creating the list within the for loop so it was cleared after each curve rather than after each plot. I still have an issue with this, but now I know what I'm looking for so I can step through the code with winpdb and see where it's breaking. Thanks, 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 Apr 3 02:11:52 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 02 Apr 2008 17:11:52 -0700 Subject: [portland] [Fwd: UG News: OSCON "Locals Only" Discount] Message-ID: <47F420C8.7030404@discorporate.us> Just in- 20% OSCON registration courtesy of O'Reilly: -------- Original Message -------- Subject: UG News: OSCON "Locals Only" Discount Date: Wed, 02 Apr 2008 16:25:16 -0800 From: Marsee Henon To: jek at discorporate.us The O'Reilly Open Source Convention (OSCON) is returning to Portland, Oregon. Once again we're offering a special discount to the locals-- User Group members in Oregon and Washington. With this "locals only" discount, your members get 20% off the registration price for OSCON. Use code "os08pdxug" when you register. To register, go to: O'Reilly Open Source Convention Oregon Convention Center 777 NE Martin Luther King, Jr. Blvd. Portland, Oregon 97232 July 21-25, 2008 Join the OSCON Facebook Group: Or Contribute to the OSCON 2008 Wiki: Hope to see you there, Marsee ================================================================ O'Reilly 1005 Gravenstein Highway North Sebastopol, CA 95472 ================================================================ From jek at discorporate.us Thu Apr 3 20:30:51 2008 From: jek at discorporate.us (jason kirtland) Date: Thu, 03 Apr 2008 11:30:51 -0700 Subject: [portland] Next Meeting: Tuesday April 8th @ 7PM Message-ID: <47F5225B.3050807@discorporate.us> Coming up fast is... The Portland Python User Group April Meeting Tuesday, 4/8 2008 at 7PM CubeSpace http://python.meetup.com/183/calendar/7515498/ See! IPython in action and learn time saving tips sliderepl, a fun shell hack that reads and executes its own source Useful tricks with Python's exec, eval and decorators Hear! Reports from PyCon 2008 Speak! Bring a question or show and tell Win! A brand new copy of Programming Python, 3rd edition A copy of Make magazine Python T-shirts Python tote bags Beer! Beer! I hope to see you all on Tuesday. Cheers, Jason From rshepard at appl-ecosys.com Fri Apr 4 00:00:27 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 3 Apr 2008 15:00:27 -0700 (PDT) Subject: [portland] Generating .tex From Python Code Message-ID: Hi, folks! I'm starting to figure out how to generate a .tex file from within a Python program. For some reason, my initial attempts are producing screwy results. I suspect those reasons are more python-related than they are LaTeX related. The attached code runs, but the output is not what I expected to see. Have I made python mistakes in the code? For example, why is the last line of the preamb comment truncated by two letters? Why are other letters missing, and the LaTeX commands written as output strings embedded in the list, rather than as LaTeX commands? Puzzled, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 -------------- next part -------------- #!/usr/bin/env python import os, sys, config preamb = """ \documentclass[oneside,english]{article} \usepackage{palatino} \usepackage[T1]{fontenc} \usepackage[latin1]{inputenc} \usepackage[dvips] {geometry} \geometry{verbose,letterpaper,tmargin=1.5cm,bmargin=1.5cm,lmargin=1.5cm,rmargin=1.5cm} \pagestyle{empty} \makeatletter \date{} \setlength\headsep{4.4cm} \setlength{\textheight}{18.5cm} \setlength{\textwidth}{25.0cm} \usepackage{babel} \makeatother \begin{document} """ ending = """\end{document}""" def econPairs(): pairData = [("Jobs","Tax base"), ("Jobs","Infrastructure"), ("Jobs","Schools"), ("Jobs","Housing"), ("Jobs","Medical care"), ("Jobs","Sustainability"), ("Jobs","Traffic volume"), ("Tax base","Infrastructure"), ("Tax base","Schools"), ("Tax base","Housing"), ("Tax base","Medical care"), ("Tax base","Sustainability"), ("Tax base","Traffic volume"), ("Infrastructure","Schools"), ("Infrastructure","Housing"), ("Infrastructure","Medical care"), ("Infrastructure","Sustainability"), ("Infrastructure","Traffic volume"), ("Schools","Housing"), ("Schools","Medical care"), ("Schools","Sustainability"), ("Schools","Traffic volume"), ("Housing","Medical care"), ("Housing","Sustainability"), ("Housing","Traffic volume"), ("Medical care","Sustainability"), ("Medical care","Traffic volume"), ("Sustainability","Traffic volume")] ratingHead = """Importance Value Definition """ ratingTab = """1 Equal importance 3 Weak importance of one over the other 5 Strong importance of one over the other 7 Demonstrated importance of one over the other 9 Absolute importance of one over the other 2, 4, 6, 8 Intermediate values between the two adjacent definitions """ instructPara = """Using the table below, determine your preference for either the first item of the pair (on the left), or the second (on the right). Use the rating table to determine the strength of your preference, then fully fill in the rectangle for that preference strength on the same line as the component pairs. If you prefer the second more than the first, also completely fill in the last box on the right.""" title = "Economic Components" out = open('omrPairs.tex', 'w') out.write(preamb) out.write(title) out.write("""\vspace{6cm}""") # space below title to line up first line with OMR form out.write('Fill in the box under \'Economic\' on this line -->') out.write("""vspace{1.5cm}""") out.write('Record your position on the project here -->') out.write("""\vspace{3cm}""") for left,right in pairData: out.write(left) out.write("""\hspace{3cm}""") out.write(right) out.write("""\end{document}""") out.close() if __name__ == "__main__": econPairs() From rshepard at appl-ecosys.com Fri Apr 4 00:05:35 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 3 Apr 2008 15:05:35 -0700 (PDT) Subject: [portland] Generating .tex From Python Code In-Reply-To: References: Message-ID: On Thu, 3 Apr 2008, Rich Shepard wrote: > I made python mistakes in the code? For example, why is the last line of the > preamb comment truncated by two letters? Why are other letters missing, OK. I suspect that \t it taken as a tab rather than a literal, and that \b is seen as bold rather than as a literal. Clues welcome! Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From hallettj at gmail.com Fri Apr 4 00:19:54 2008 From: hallettj at gmail.com (Jesse Hallett) Date: Thu, 03 Apr 2008 15:19:54 -0700 Subject: [portland] Generating .tex From Python Code In-Reply-To: References: Message-ID: <47F5580A.9090905@gmail.com> Since backslashes are generally parsed as escape characters, I believe you would get the right results if you replaced all of the backslashes (\) in strings with double backslashes (\\). Be aware that some languages treat backslashes as escape characters in strings enclosed in double quotes (") but in strings enclosed in single quotes('). I don't remember whether Python does this; but if it does, then another solution would be to replace all of your double quotes with single quotes. Cheers, Jesse Rich Shepard wrote: > On Thu, 3 Apr 2008, Rich Shepard wrote: > >> I made python mistakes in the code? For example, why is the last line of the >> preamb comment truncated by two letters? Why are other letters missing, > > OK. I suspect that \t it taken as a tab rather than a literal, and that \b > is seen as bold rather than as a literal. > > Clues welcome! > > Rich > From hallettj at gmail.com Fri Apr 4 00:30:50 2008 From: hallettj at gmail.com (Jesse Hallett) Date: Thu, 03 Apr 2008 15:30:50 -0700 Subject: [portland] Generating .tex From Python Code In-Reply-To: References: Message-ID: <47F55A9A.1090203@gmail.com> I forgot to include this relevant bit of information in my last message: http://xkcd.com/234/ Cheers, Jesse Rich Shepard wrote: > On Thu, 3 Apr 2008, Rich Shepard wrote: > >> I made python mistakes in the code? For example, why is the last line of the >> preamb comment truncated by two letters? Why are other letters missing, > > OK. I suspect that \t it taken as a tab rather than a literal, and that \b > is seen as bold rather than as a literal. > > Clues welcome! > > Rich > From adam at therobots.org Fri Apr 4 00:38:38 2008 From: adam at therobots.org (Adam Lowry) Date: Thu, 3 Apr 2008 15:38:38 -0700 Subject: [portland] Generating .tex From Python Code In-Reply-To: <47F5580A.9090905@gmail.com> References: <47F5580A.9090905@gmail.com> Message-ID: <772FA1BF-82CF-46AC-BB21-2531E8E63FC3@therobots.org> If you want to avoid backslashes being treated as control chars in strings, prefix them with r: str = r"[\%#]*" I often use this with regular expressions. On Apr 3, 2008, at 3:19 PM, Jesse Hallett wrote: > Since backslashes are generally parsed as escape characters, I believe > you would get the right results if you replaced all of the backslashes > (\) in strings with double backslashes (\\). > > Be aware that some languages treat backslashes as escape characters in > strings enclosed in double quotes (") but in strings enclosed in > single > quotes('). I don't remember whether Python does this; but if it does, > then another solution would be to replace all of your double quotes > with > single quotes. > > Cheers, > Jesse > > Rich Shepard wrote: >> On Thu, 3 Apr 2008, Rich Shepard wrote: >> >>> I made python mistakes in the code? For example, why is the last >>> line of the >>> preamb comment truncated by two letters? Why are other letters >>> missing, >> >> OK. I suspect that \t it taken as a tab rather than a literal, >> and that \b >> is seen as bold rather than as a literal. >> >> Clues welcome! >> >> Rich >> > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland From rshepard at appl-ecosys.com Fri Apr 4 00:39:50 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 3 Apr 2008 15:39:50 -0700 (PDT) Subject: [portland] Generating .tex From Python Code In-Reply-To: <47F5580A.9090905@gmail.com> References: <47F5580A.9090905@gmail.com> Message-ID: On Thu, 3 Apr 2008, Jesse Hallett wrote: > Since backslashes are generally parsed as escape characters, I believe you > would get the right results if you replaced all of the backslashes (\) in > strings with double backslashes (\\). Jesse, Yup. That fixed many of the problems. I totally forgot about needing double slashes. Now to figure out why the embedded commands aren't working; that may also be a matter of proper marking. 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 Apr 4 00:45:35 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 3 Apr 2008 15:45:35 -0700 (PDT) Subject: [portland] Generating .tex From Python Code In-Reply-To: <47F55A9A.1090203@gmail.com> References: <47F55A9A.1090203@gmail.com> Message-ID: On Thu, 3 Apr 2008, Jesse Hallett wrote: > I forgot to include this relevant bit of information in my last message: > http://xkcd.com/234/ Of course! 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 Apr 4 01:15:33 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 3 Apr 2008 16:15:33 -0700 (PDT) Subject: [portland] Generating .tex From Python Code In-Reply-To: <772FA1BF-82CF-46AC-BB21-2531E8E63FC3@therobots.org> References: <47F5580A.9090905@gmail.com> <772FA1BF-82CF-46AC-BB21-2531E8E63FC3@therobots.org> Message-ID: On Thu, 3 Apr 2008, Adam Lowry wrote: > If you want to avoid backslashes being treated as control chars in > strings, prefix them with r: > str = r"[\%#]*" Ah, so! The 'r' means treat the string as raw text, then. I wondered what it meant when I saw that used. Thanks, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From markgross at thegnar.org Mon Apr 7 20:16:27 2008 From: markgross at thegnar.org (markgross at thegnar.org) Date: Mon, 7 Apr 2008 14:16:27 -0400 (EDT) Subject: [portland] ipython demo talk slides. Message-ID: <44043.134.134.136.2.1207592187.squirrel@email.powweb.com> this time in open office format. (lots smaller) -------------- next part -------------- A non-text attachment was scrubbed... Name: ipython_demo.odp Type: application/vnd.oasis.opendocument.presentation Size: 19225 bytes Desc: not available Url : http://mail.python.org/pipermail/portland/attachments/20080407/48f66383/attachment.odp From marcus.e at gmail.com Tue Apr 8 06:57:26 2008 From: marcus.e at gmail.com (marcus estes) Date: Mon, 7 Apr 2008 21:57:26 -0700 Subject: [portland] Google App Engine Message-ID: Hey Python Folks, Did anyone else catch the release of the new Google cloud computing service for Python apps? http://appengine.google.com The first 10,000 dev accounts went like hotcakes and I lucked into one. I need help with my test app though - would anyone like to pitch in and help? Hit me up offlist. Thanks, Marcus (http://marcusestes.com/) From andy.grover at gmail.com Tue Apr 8 11:28:55 2008 From: andy.grover at gmail.com (Andrew Grover) Date: Tue, 8 Apr 2008 02:28:55 -0700 Subject: [portland] Google App Engine In-Reply-To: References: Message-ID: On Mon, Apr 7, 2008 at 9:57 PM, marcus estes wrote: > Did anyone else catch the release of the new Google cloud computing > service for Python apps? > http://appengine.google.com Very cool, should be a big boost for Python. -- Andy From python at dylanreinhardt.com Tue Apr 8 15:03:47 2008 From: python at dylanreinhardt.com (Dylan Reinhardt) Date: Tue, 8 Apr 2008 06:03:47 -0700 Subject: [portland] Google App Engine In-Reply-To: References: Message-ID: <4c645a720804080603h337092by743cdb8473444387@mail.gmail.com> If you have a Google Apps for Domains account, it looks like you can still sneak an invitation to the preview. Go hit: http://appengine.google.com/a// Then use the button that says it's for the waiting list... I was only on the waiting list a couple hours. In case that's helpful to someone else.... Dylan On Mon, Apr 7, 2008 at 9:57 PM, marcus estes wrote: > Hey Python Folks, > > Did anyone else catch the release of the new Google cloud computing > service for Python apps? > http://appengine.google.com > > The first 10,000 dev accounts went like hotcakes and I lucked into > one. I need help with my test app though - would anyone like to pitch > in and help? Hit me up offlist. > > Thanks, > Marcus > (http://marcusestes.com/) > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From jek at discorporate.us Tue Apr 8 19:09:53 2008 From: jek at discorporate.us (jason kirtland) Date: Tue, 08 Apr 2008 10:09:53 -0700 Subject: [portland] TONIGHT! Meeting @ 7pm, CubeSpace Message-ID: <47FBA6E1.6090705@discorporate.us> Just a reminder that we're meeting tonight, 7PM at CubeSpace. http://python.meetup.com/183/calendar/7515498/ PLUS there are more books in the grab bag for tonight, courtesy of O'Reilly: The ThoughtWorks Anthology (Pragmatic Bookshelf) Visualizing Data (O'Reilly) And Google's AppEngine will probably be mentioned once or twice. ;) See you all tonight! Jason From rshepard at appl-ecosys.com Tue Apr 8 20:05:41 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 8 Apr 2008 11:05:41 -0700 (PDT) Subject: [portland] TONIGHT! Meeting @ 7pm, CubeSpace In-Reply-To: <47FBA6E1.6090705@discorporate.us> References: <47FBA6E1.6090705@discorporate.us> Message-ID: On Tue, 8 Apr 2008, jason kirtland wrote: > Just a reminder that we're meeting tonight, 7PM at CubeSpace. Jason, I have a conflict so I will not be able to make it. 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 Tue Apr 8 22:20:47 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 8 Apr 2008 13:20:47 -0700 (PDT) Subject: [portland] A Question of Directories Message-ID: I have LaTeX generation embedded in the python functions, and it works great. However, when I automate running pdflatex, the output is not in the same directory as the .tex file. In the model directory (where the .py files live) is a subdirectory called reports/. Python is directed to open, write to, and close files in that directory. It does so. But, when I issue the command os.system('pdflatex ./reports/omrPairs.tex') the resulting .aux, .log, and .pdf files are in the parent directory, not the reports/ subdirectory. What syntax will direct pdflatex to put the output in the subdirectory? Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From adam at therobots.org Tue Apr 8 22:34:37 2008 From: adam at therobots.org (Adam Lowry) Date: Tue, 08 Apr 2008 13:34:37 -0700 Subject: [portland] A Question of Directories In-Reply-To: References: Message-ID: <47FBD6DD.5000009@therobots.org> Rich Shepard wrote: > But, when I issue the command > os.system('pdflatex ./reports/omrPairs.tex') > > the resulting .aux, .log, and .pdf files are in the parent directory, not > the reports/ subdirectory. > I don't have pdflatex handy, but I imagine it defaults to dumping output into the current working directory. There might be a command line option, but if not you can either: import os os.chdir('tmp') os.system('pdflatex ./reports/omrPairs.tex') Or use the subprocess module instead of os.system, which has a working directory option: import subprocess subprocess.call(['pdflatex', './reports/omrPairs.tex'], cwd='reports') Adam From rshepard at appl-ecosys.com Tue Apr 8 22:47:49 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 8 Apr 2008 13:47:49 -0700 (PDT) Subject: [portland] A Question of Directories In-Reply-To: <47FBD6DD.5000009@therobots.org> References: <47FBD6DD.5000009@therobots.org> Message-ID: On Tue, 8 Apr 2008, Adam Lowry wrote: > os.chdir('tmp') Thanks, Adam. That'll do nicely. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From hallettj at gmail.com Wed Apr 9 00:08:08 2008 From: hallettj at gmail.com (Jesse Hallett) Date: Tue, 08 Apr 2008 15:08:08 -0700 Subject: [portland] A Question of Directories In-Reply-To: References: Message-ID: <47FBECC8.6000803@gmail.com> os.system('pdflatex -output-directory reports/ omrPairs.tex') You can find more information by running the command 'man pdflatex'. Cheers, Jesse Rich Shepard wrote: > I have LaTeX generation embedded in the python functions, and it works > great. However, when I automate running pdflatex, the output is not in the > same directory as the .tex file. > > In the model directory (where the .py files live) is a subdirectory called > reports/. Python is directed to open, write to, and close files in that > directory. It does so. > > But, when I issue the command > os.system('pdflatex ./reports/omrPairs.tex') > > the resulting .aux, .log, and .pdf files are in the parent directory, not > the reports/ subdirectory. > > What syntax will direct pdflatex to put the output in the subdirectory? > > Rich > From rshepard at appl-ecosys.com Wed Apr 9 00:19:19 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 8 Apr 2008 15:19:19 -0700 (PDT) Subject: [portland] A Question of Directories In-Reply-To: <47FBECC8.6000803@gmail.com> References: <47FBECC8.6000803@gmail.com> Message-ID: On Tue, 8 Apr 2008, Jesse Hallett wrote: > os.system('pdflatex -output-directory reports/ omrPairs.tex') Jesse, Thank you. That'll work, too. 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 Apr 9 21:58:29 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 09 Apr 2008 12:58:29 -0700 Subject: [portland] Resources from the April meeting Message-ID: <47FD1FE5.4010503@discorporate.us> Here are some links to topics discussed at the April meeting: IPython http://ipython.scipy.org/ sliderepl http://discorporate.us/projects/sliderepl/ Using inspect + exec to match function signatures http://discorporate.us/jek/python/inspectexec.py Google App Engine http://code.google.com/appengine/ And keeping with the shell theme, try App Engine here: http://shell.appspot.com/ Cheers, Jason From mccredie at gmail.com Thu Apr 10 01:46:51 2008 From: mccredie at gmail.com (Matt McCredie) Date: Wed, 9 Apr 2008 16:46:51 -0700 Subject: [portland] Follow up to last night Message-ID: <9e95df10804091646i4f15e2edk9b22995b7b2cee75@mail.gmail.com> Hi all, Last night Jason gave a demo "Using inspect + exec to match function signatures". He mentioned that the decorated function still didn't have the correct filename. I brought something up, I don't think anybody really followed what I was saying. Anyway, here is what I was getting at, and it seems to work. Seems to work. Feedback welcome. Matt [code] import codeop import inspect import warnings def deprecated(fn): """Decorate a function and issue a deprecation warning on execution.""" spec = inspect.getargspec(fn) func_name = fn.func_name argspec = inspect.formatargspec(*spec) callspec = inspect.formatargspec(*spec[:3]) # adding newlines seems to be the easiest way to get the line number to # report correctly. text = "\n"*fn.func_code.co_firstlineno + """\ def %(func_name)s%(argspec)s: warnings.warn(DeprecationWarning('%(func_name)s')) return fn%(callspec)s """ text %= locals() # compile it with the appropriate file name code = codeop.compile_command(text, fn.func_code.co_filename, "exec") env = locals().copy() env['warnings'] = warnings # just exec the code object instead of the string exec code in env env[func_name].func_doc = fn.func_doc return env[func_name] [/code] From richardson.michael.t at gmail.com Tue Apr 15 23:21:04 2008 From: richardson.michael.t at gmail.com (Michael Richardson) Date: Tue, 15 Apr 2008 14:21:04 -0700 Subject: [portland] Portland Django User Group In-Reply-To: <47FD1FE5.4010503@discorporate.us> References: <47FD1FE5.4010503@discorporate.us> Message-ID: <03C256B6-5733-4FF4-AAD5-6A2D30262D6B@gmail.com> Hi everyone, I just wanted to let you know that we started a Portland Django User Group. The mailing list is here: http://groups.google.com/group/pdxdjango - feel free to join up, even if you're only curious about Django. This is brand new so feel free to get involved and send requests along. Thanks! -Michael From freyley at gmail.com Tue Apr 15 23:24:54 2008 From: freyley at gmail.com (Jeff Schwaber) Date: Tue, 15 Apr 2008 14:24:54 -0700 Subject: [portland] Portland Django User Group In-Reply-To: <03C256B6-5733-4FF4-AAD5-6A2D30262D6B@gmail.com> References: <47FD1FE5.4010503@discorporate.us> <03C256B6-5733-4FF4-AAD5-6A2D30262D6B@gmail.com> Message-ID: <8db4a1910804151424t6c4ec970ia35d2f1f28b71689@mail.gmail.com> On Tue, Apr 15, 2008 at 2:21 PM, Michael Richardson wrote: > Hi everyone, > I just wanted to let you know that we started a Portland Django User > Group. The mailing list is here: http://groups.google.com/group/pdxdjango > - feel free to join up, even if you're only curious about Django. > This is brand new so feel free to get involved and send requests along. > Thanks! > -Michael That's awesome, Michael. I hope this encourages people to get a deeper look at Django. Are you going to be meeting, and if so, when? Thanks, Jeff _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From richardson.michael.t at gmail.com Wed Apr 16 00:05:34 2008 From: richardson.michael.t at gmail.com (Michael Richardson) Date: Tue, 15 Apr 2008 15:05:34 -0700 Subject: [portland] Portland Django User Group In-Reply-To: <8db4a1910804151424t6c4ec970ia35d2f1f28b71689@mail.gmail.com> References: <47FD1FE5.4010503@discorporate.us> <03C256B6-5733-4FF4-AAD5-6A2D30262D6B@gmail.com> <8db4a1910804151424t6c4ec970ia35d2f1f28b71689@mail.gmail.com> Message-ID: <385BEC07-C787-445C-8A53-0BC07D908982@gmail.com> On Apr 15, 2008, at 2:24 PM, Jeff Schwaber wrote: > Are you going to be meeting, and if so, when? Yessir - our first meetup is tomorrow, April 16, 5pm at Bailey's Taproom. The Upcoming page is here: http://upcoming.yahoo.com/event/474053/ and announcement is here: http://groups.google.com/group/pdxdjango/browse_thread/thread/7e08db2b4b1d1cdb Thanks! -Michael From rshepard at appl-ecosys.com Wed Apr 16 20:48:45 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Apr 2008 11:48:45 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems Message-ID: I have a mental block on understanding just how to index a list of tuples so I can extract the data in an orderly fashion. The list looks like this: [(A,1),(A,2), ... (A,8),(B,1),(B,2), ... (B,8),(C,1),(C2), ... (C,8)] What I want to do is extract all tuples grouped by the first element, then list the associated second elements). That is, A 1 2 ... 8 B 1 2 ... 8 etc. Referencing list[0] returns the first tuple; list[0][0] returns the first item in the first tuple; but I cannot cycle through the three first items extracting the second items associated with each. I've looked at my books and previous threads here, but I'm just not getting how this is done. I've played with list comprehensions, zip, and other tools without getting the proper syntax or results I need. Don't know why the answer keeps eluding me, but it does. 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 Apr 16 21:07:41 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Apr 2008 12:07:41 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: <48064E7D.6050208@discorporate.us> Rich Shepard wrote: > I have a mental block on understanding just how to index a list of tuples > so I can extract the data in an orderly fashion. > > The list looks like this: [(A,1),(A,2), ... (A,8),(B,1),(B,2), ... > (B,8),(C,1),(C2), ... (C,8)] > > What I want to do is extract all tuples grouped by the first element, then > list the associated second elements). That is, > A > 1 > 2 > ... > 8 > > B > 1 > 2 > ... > 8 > etc. > > Referencing list[0] returns the first tuple; list[0][0] returns the first > item in the first tuple; but I cannot cycle through the three first items > extracting the second items associated with each. > > I've looked at my books and previous threads here, but I'm just not > getting how this is done. I've played with list comprehensions, zip, and > other tools without getting the proper syntax or results I need. Don't know > why the answer keeps eluding me, but it does. A, B, C = 'A', 'B', 'C' list_o_tuples = [ (A,1), (A,2), (A, '...'), (A,8), (B,1), (B,2), (B, '...'), (B,8), (C,1), (C,2), (C, '...'), (C,8)] # option 1) charge through the flat list and keep a flag previous = None for left, right in list_o_tuples: if left != previous: print left previous = left print "\t", right # option 2) make groups, each sharing a common 'left' item from itertools import groupby from operator import itemgetter for left, grouped in groupby(list_o_tuples, itemgetter(0)): print left for left_again, right in grouped: print "\t", right # look under the hood at what groupby() does in 2) for left, grouped in groupby(list_o_tuples, itemgetter(0)): print left, list(grouped) From kirby.urner at gmail.com Wed Apr 16 21:13:39 2008 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 16 Apr 2008 12:13:39 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: You could use list comprensions: >>> mydata [('A', 1), ('A', 2), ('A', 8), ('B', 1), ('B', 2), ('B', 8), ('C', 1), ('C', 2), ('C', 8)] >>> astuff = [j for (i,j) in mydata if i == 'A'] >>> astuff [1, 2, 8] >>> bstuff = [j for (i,j) in mydata if i == 'B'] >>> bstuff [1, 2, 8] If you don't know what all the keys are gonna be you could build a list of unique ones: >>> thekeys = set([i for (i,j) in mydata]) >>> thekeys set(['A', 'C', 'B']) >>> for thekey in thekeys: print thekey print [j for (i,j) in mydata if i == thekey] A [1, 2, 8] C [1, 2, 8] B [1, 2, 8] Note there's no presumption the As, Bs are clumped together. Kirby On Wed, Apr 16, 2008 at 11:48 AM, Rich Shepard wrote: > I have a mental block on understanding just how to index a list of tuples > so I can extract the data in an orderly fashion. > > The list looks like this: [(A,1),(A,2), ... (A,8),(B,1),(B,2), ... > (B,8),(C,1),(C2), ... (C,8)] > > What I want to do is extract all tuples grouped by the first element, then > list the associated second elements). That is, > A > 1 > 2 > ... > 8 > > B > 1 > 2 > ... > 8 > etc. > > Referencing list[0] returns the first tuple; list[0][0] returns the first > item in the first tuple; but I cannot cycle through the three first items > extracting the second items associated with each. > > I've looked at my books and previous threads here, but I'm just not > getting how this is done. I've played with list comprehensions, zip, and > other tools without getting the proper syntax or results I need. Don't know > why the answer keeps eluding me, but it does. > > 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 rshepard at appl-ecosys.com Wed Apr 16 21:14:43 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Apr 2008 12:14:43 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <48064E7D.6050208@discorporate.us> References: <48064E7D.6050208@discorporate.us> Message-ID: On Wed, 16 Apr 2008, jason kirtland wrote: > # option 2) make groups, each sharing a common 'left' item > from itertools import groupby > from operator import itemgetter > > for left, grouped in groupby(list_o_tuples, itemgetter(0)): > print left > for left_again, right in grouped: > print "\t", right > > # look under the hood at what groupby() does in 2) > for left, grouped in groupby(list_o_tuples, itemgetter(0)): > print left, list(grouped) Thanks, Jason. I obviously still don't fully understand 'groupedby', but This is what I need to create nested for loops. Hope it sticks this time! 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 Wed Apr 16 21:21:29 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Apr 2008 12:21:29 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: On Wed, 16 Apr 2008, kirby urner wrote: > You could use list comprensions: >>>> astuff = [j for (i,j) in mydata if i == 'A'] Kirby, I thought of trying this, but I want to make it general rather than explicit ... > If you don't know what all the keys are gonna be you could build a list of > unique ones: ... as you show here. >>>> thekeys = set([i for (i,j) in mydata]) > >>>> thekeys > set(['A', 'C', 'B']) > >>>> for thekey in thekeys: > print thekey > print [j for (i,j) in mydata if i == thekey] I need to read and learn about sets in python. Now I have two approaches as solutions when I again run into the same need. Thank you very much, 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 Wed Apr 16 21:28:12 2008 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 16 Apr 2008 12:28:12 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: On Wed, Apr 16, 2008 at 12:21 PM, Rich Shepard wrote: > On Wed, 16 Apr 2008, kirby urner wrote: << SNIP >> > >>>> thekeys = set([i for (i,j) in mydata]) > > > >>>> thekeys > > set(['A', 'C', 'B']) > > > >>>> for thekey in thekeys: > > print thekey > > print [j for (i,j) in mydata if i == thekey] > > I need to read and learn about sets in python. > I forget in which version you don't need to import, but by 2.5 they're built-in native. Because sets don't allow duplicates, they're a quick way to scan through a list while purging duplicates e.g. >>> set(['A','A','B','B']) set(['A', 'B']) > Now I have two approaches as solutions when I again run into the same > need. > The list comprehensions approach is based on filtration i.e. no pre-sorting of your data to ensure clumping on the key. Not super efficient, but maybe OK for smallish data sets (10K elements or whatever). Remember, your time is more valuable than your machine's and sometimes slower code is better if it's more readable / maintainable by you and your peers. Kirby > Thank you very much, > > > > 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 jek at discorporate.us Wed Apr 16 21:33:22 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Apr 2008 12:33:22 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: <48064E7D.6050208@discorporate.us> Message-ID: <48065482.8010106@discorporate.us> Rich Shepard wrote: > On Wed, 16 Apr 2008, jason kirtland wrote: > >> # option 2) make groups, each sharing a common 'left' item >> from itertools import groupby >> from operator import itemgetter >> >> for left, grouped in groupby(list_o_tuples, itemgetter(0)): >> print left >> for left_again, right in grouped: >> print "\t", right >> >> # look under the hood at what groupby() does in 2) >> for left, grouped in groupby(list_o_tuples, itemgetter(0)): >> print left, list(grouped) > > Thanks, Jason. I obviously still don't fully understand 'groupedby', but > This is what I need to create nested for loops. > Maybe implementing the 'itemgetter' and 'groupby' library functions from scratch will illuminate them. 'groupby' is just a canned version of the option 1) from my last post: Python 2.5.1 (r251:54863, May 23 2007, 16:25:53) [GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def itemgetter(index): ... def get_it(obj): ... return obj[index] ... return get_it ... >>> a_list = ['x', 'y', 'z'] >>> getter = itemgetter(1) >>> getter >>> getter(a_list) 'y' >>> getter(['item 0', 'item 1', 'item 2']) 'item 1' >>> def groupby(sequence, key_function): ... results = [] ... current_key, group = None, [] ... for item in sequence: ... print "considering", item ... key = key_function(item) ... if key != current_key: ... print "new key", key, "starting new group" ... current_key = key ... group = [] ... results.append((key, group)) ... print "adding", item, "to group" ... group.append(item) ... return results ... >>> some_pairs = [('A', 1), ('A', 2), ('B', 1), ('B', 2)] >>> for grouped_by, grouping in groupby(some_pairs, itemgetter(0)): ... print "grouped_by", grouped_by ... print "grouping", grouping ... considering ('A', 1) new key A starting new group adding ('A', 1) to group considering ('A', 2) adding ('A', 2) to group considering ('B', 1) new key B starting new group adding ('B', 1) to group considering ('B', 2) adding ('B', 2) to group grouped_by A grouping [('A', 1), ('A', 2)] grouped_by B grouping [('B', 1), ('B', 2)] From rshepard at appl-ecosys.com Wed Apr 16 21:41:12 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Apr 2008 12:41:12 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <48065482.8010106@discorporate.us> References: <48064E7D.6050208@discorporate.us> <48065482.8010106@discorporate.us> Message-ID: On Wed, 16 Apr 2008, jason kirtland wrote: > Maybe implementing the 'itemgetter' and 'groupby' library functions from > scratch will illuminate them. 'groupby' is just a canned version of the > option 1) from my last post: Thanks, Jason. I'll read and learn. 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 Apr 16 21:48:47 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Apr 2008 12:48:47 -0700 Subject: [portland] Follow up to last night In-Reply-To: <9e95df10804091646i4f15e2edk9b22995b7b2cee75@mail.gmail.com> References: <9e95df10804091646i4f15e2edk9b22995b7b2cee75@mail.gmail.com> Message-ID: <4806581F.8090504@discorporate.us> Matt McCredie wrote: > Hi all, > > Last night Jason gave a demo "Using inspect + exec to match > function signatures". He mentioned that the decorated function still > didn't have the correct filename. I brought something up, I don't > think anybody really followed what I was saying. Anyway, here is what > I was getting at, and it seems to work. > > Seems to work. Feedback welcome. > > Matt > > [code] > import codeop > import inspect > import warnings > > def deprecated(fn): > """Decorate a function and issue a deprecation warning on execution.""" > spec = inspect.getargspec(fn) > func_name = fn.func_name > argspec = inspect.formatargspec(*spec) > callspec = inspect.formatargspec(*spec[:3]) > > # adding newlines seems to be the easiest way to get the line number to > # report correctly. > > text = "\n"*fn.func_code.co_firstlineno + """\ > def %(func_name)s%(argspec)s: > warnings.warn(DeprecationWarning('%(func_name)s')) > return fn%(callspec)s > """ > text %= locals() > > # compile it with the appropriate file name > code = codeop.compile_command(text, fn.func_code.co_filename, "exec") > > env = locals().copy() > env['warnings'] = warnings > > # just exec the code object instead of the string > exec code in env > env[func_name].func_doc = fn.func_doc > return env[func_name] > [/code] Nice. The last step would be to get 'inspect.getsourcelines' to return the source of the generated decorator, rather than the decoratee: def a(): print 'a!' print inspect.getsourcelines(a) source = inspect.getsourcelines(a)[0] @deprecated def a(): print 'a!' print inspect.getsourcelines(a) assert source != inspect.getsourcelines(a)[0] (...and preferably without monkeypatching in the stdlib. ;) From python at dylanreinhardt.com Wed Apr 16 22:48:14 2008 From: python at dylanreinhardt.com (Dylan Reinhardt) Date: Wed, 16 Apr 2008 13:48:14 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> Another approach to add to the pile: >>> my_tuples = [('A',1),('A',2), ('A',3), ('A',4), ('B',1), ('B',2), ('B',3), ('B',4)] >>> grouper = {} >>> for left, right in my_tuples: ... grouper.setdefault(left, []).append(right) ... now you have a dict with values groped by keys, as shown below... >>> for key in grouper.keys(): ... print key ... for value in grouper[key]: ... print '\t%s' % value ... A 1 2 3 4 B 1 2 3 4 HTH, Dylan On Wed, Apr 16, 2008 at 11:48 AM, Rich Shepard wrote: > I have a mental block on understanding just how to index a list of tuples > so I can extract the data in an orderly fashion. > > The list looks like this: [(A,1),(A,2), ... (A,8),(B,1),(B,2), ... > (B,8),(C,1),(C2), ... (C,8)] > > What I want to do is extract all tuples grouped by the first element, then > list the associated second elements). That is, > A > 1 > 2 > ... > 8 > > B > 1 > 2 > ... > 8 > etc. > > Referencing list[0] returns the first tuple; list[0][0] returns the first > item in the first tuple; but I cannot cycle through the three first items > extracting the second items associated with each. > > I've looked at my books and previous threads here, but I'm just not > getting how this is done. I've played with list comprehensions, zip, and > other tools without getting the proper syntax or results I need. Don't know > why the answer keeps eluding me, but it does. > > 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 Thu Apr 17 00:08:51 2008 From: mccredie at gmail.com (Matt McCredie) Date: Wed, 16 Apr 2008 15:08:51 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> Message-ID: <9e95df10804161508y5583757dl3cb07f851af1db28@mail.gmail.com> On Wed, Apr 16, 2008 at 1:48 PM, Dylan Reinhardt wrote: > Another approach to add to the pile: > > >>> my_tuples = [('A',1),('A',2), ('A',3), ('A',4), ('B',1), ('B',2), > ('B',3), ('B',4)] > >>> grouper = {} > >>> for left, right in my_tuples: > ... grouper.setdefault(left, []).append(right) > ... > > now you have a dict with values groped by keys, as shown below... > > >>> for key in grouper.keys(): > ... print key > ... for value in grouper[key]: > ... print '\t%s' % value > ... > A > 1 > 2 > 3 > 4 > B > 1 > 2 > 3 > 4 > > > HTH, > > Dylan > Just to append to Dylan's response, you can get something similar with `defaultdict`. >>> from collections import defaultdict >>> my_tuples = [('A',1),('A',2), ('A',3), ('A',4), ('B',1), ('B',2), ('B',3), ('B',4)] >>> grouper = defaultdict(list) >>> for left, right in my_tuples: ... grouper[left].append(right) ... The rest remains the same. Info on defaultdict: http://docs.python.org/lib/defaultdict-objects.html Matt From rshepard at appl-ecosys.com Thu Apr 17 00:23:29 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Apr 2008 15:23:29 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> Message-ID: On Wed, 16 Apr 2008, Dylan Reinhardt wrote: > Another approach to add to the pile: > >>>> my_tuples = [('A',1),('A',2), ('A',3), ('A',4), ('B',1), ('B',2), > ('B',3), ('B',4)] >>>> grouper = {} >>>> for left, right in my_tuples: > ... grouper.setdefault(left, []).append(right) > ... > > now you have a dict with values groped by keys, as shown below... > >>>> for key in grouper.keys(): > ... print key > ... for value in grouper[key]: > ... print '\t%s' % value > ... > A > 1 > 2 > 3 > 4 > B > 1 > 2 > 3 > 4 Dylan, Thank you for expanding my horizons. While all the examples print the right side item of each tuple, I need to interate through those for each left side item. It's fighting me, but that's my lack of python experience showing up. I'll get there. Much 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 Thu Apr 17 00:35:00 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Apr 2008 15:35:00 -0700 Subject: [portland] BarCamp Portland: May 2nd-4th @ CubeSpace Message-ID: <48067F14.6010700@discorporate.us> BarCamp Portland is coming up in just a couple weeks! From http://barcampportland.org : "BarCamp Portland is an unconference for the Portland tech community, produced BY the Portland tech community. "BarCamp is an ad-hoc gathering born from the desire for people to share and learn in an open environment. It is an intense event with discussions, demos, and interaction from participants. You never quite know what to expect at BarCamp. When you arrive on Friday, there will be an agenda framework (times / rooms), but the content for the sessions will be decided by the participants." Last year's BarCamp was fantastic and this year will no doubt be as well. There will probably even be Python sessions. And it's free! BarCamp is still in need of sponsors this year. If you know of an organization that might be interested in sponsoring, put them in touch with Selena. BarCamp Portland 2 May 2, 3, & 4 http://barcampportland.org http://upcoming.yahoo.com/event/421147 Cheers, Jason From kirby.urner at gmail.com Thu Apr 17 01:09:10 2008 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 16 Apr 2008 16:09:10 -0700 Subject: [portland] BarCamp Portland: May 2nd-4th @ CubeSpace In-Reply-To: <48067F14.6010700@discorporate.us> References: <48067F14.6010700@discorporate.us> Message-ID: What's the process for editing the Wiki (invite key?). I was going to say maybe could present on J language, since exotic languages might get focus. Kirby On Wed, Apr 16, 2008 at 3:35 PM, jason kirtland wrote: > BarCamp Portland is coming up in just a couple weeks! > > From http://barcampportland.org : > > "BarCamp Portland is an unconference for the Portland tech community, > produced BY the Portland tech community. > > "BarCamp is an ad-hoc gathering born from the desire for people to share > and learn in an open environment. It is an intense event with > discussions, demos, and interaction from participants. You never quite > know what to expect at BarCamp. When you arrive on Friday, there will be > an agenda framework (times / rooms), but the content for the sessions > will be decided by the participants." > > Last year's BarCamp was fantastic and this year will no doubt be as > well. There will probably even be Python sessions. And it's free! > > BarCamp is still in need of sponsors this year. If you know of an > organization that might be interested in sponsoring, put them in touch > with Selena. > > BarCamp Portland 2 > May 2, 3, & 4 > http://barcampportland.org > http://upcoming.yahoo.com/event/421147 > > Cheers, > Jason > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From jek at discorporate.us Thu Apr 17 01:20:12 2008 From: jek at discorporate.us (jason kirtland) Date: Wed, 16 Apr 2008 16:20:12 -0700 Subject: [portland] BarCamp Portland: May 2nd-4th @ CubeSpace In-Reply-To: References: <48067F14.6010700@discorporate.us> Message-ID: <480689AC.9090201@discorporate.us> It's hiding there on the bottom left (after clicking "edit page"). kirby urner wrote: > What's the process for editing the Wiki (invite key?). I was going > to say maybe could present on J language, since exotic languages > might get focus. > > Kirby > > > On Wed, Apr 16, 2008 at 3:35 PM, jason kirtland wrote: >> BarCamp Portland is coming up in just a couple weeks! >> >> From http://barcampportland.org : >> >> "BarCamp Portland is an unconference for the Portland tech community, >> produced BY the Portland tech community. >> >> "BarCamp is an ad-hoc gathering born from the desire for people to share >> and learn in an open environment. It is an intense event with >> discussions, demos, and interaction from participants. You never quite >> know what to expect at BarCamp. When you arrive on Friday, there will be >> an agenda framework (times / rooms), but the content for the sessions >> will be decided by the participants." >> >> Last year's BarCamp was fantastic and this year will no doubt be as >> well. There will probably even be Python sessions. And it's free! >> >> BarCamp is still in need of sponsors this year. If you know of an >> organization that might be interested in sponsoring, put them in touch >> with Selena. >> >> BarCamp Portland 2 >> May 2, 3, & 4 >> http://barcampportland.org >> http://upcoming.yahoo.com/event/421147 >> >> Cheers, >> Jason >> _______________________________________________ >> Portland mailing list >> Portland at python.org >> http://mail.python.org/mailman/listinfo/portland >> > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From python at dylanreinhardt.com Thu Apr 17 01:20:44 2008 From: python at dylanreinhardt.com (Dylan Reinhardt) Date: Wed, 16 Apr 2008 16:20:44 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <9e95df10804161508y5583757dl3cb07f851af1db28@mail.gmail.com> References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> <9e95df10804161508y5583757dl3cb07f851af1db28@mail.gmail.com> Message-ID: <4c645a720804161620q7c691839ue367cd1f91bedd3f@mail.gmail.com> Oh cool! Pretty soon Python will have a built-in object for *every* useful algo I've ever learned. :-) Perhaps we're already there... D. On Wed, Apr 16, 2008 at 3:08 PM, Matt McCredie wrote: > > On Wed, Apr 16, 2008 at 1:48 PM, Dylan Reinhardt > wrote: > > Another approach to add to the pile: > > > > >>> my_tuples = [('A',1),('A',2), ('A',3), ('A',4), ('B',1), ('B',2), > > ('B',3), ('B',4)] > > >>> grouper = {} > > >>> for left, right in my_tuples: > > ... grouper.setdefault(left, []).append(right) > > ... > > > > now you have a dict with values groped by keys, as shown below... > > > > >>> for key in grouper.keys(): > > ... print key > > ... for value in grouper[key]: > > ... print '\t%s' % value > > ... > > A > > 1 > > 2 > > 3 > > 4 > > B > > 1 > > 2 > > 3 > > 4 > > > > > > HTH, > > > > Dylan > > > > Just to append to Dylan's response, you can get something similar with > `defaultdict`. > > >>> from collections import defaultdict > > >>> my_tuples = [('A',1),('A',2), ('A',3), ('A',4), ('B',1), ('B',2), > ('B',3), ('B',4)] > >>> grouper = defaultdict(list) > > >>> for left, right in my_tuples: > ... grouper[left].append(right) > ... > > The rest remains the same. > > Info on defaultdict: http://docs.python.org/lib/defaultdict-objects.html > > Matt > > > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From rshepard at appl-ecosys.com Thu Apr 17 01:24:48 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Apr 2008 16:24:48 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: On Wed, 16 Apr 2008, kirby urner wrote: >>>> thekeys = set([i for (i,j) in mydata]) I thought this more elegant, but when I could not use the 'j' values associated with each 'i' value I did some reading on sets. They are iterable, but not indexable. And I need to access each 'j' associated with each 'i'. But, I learned quite a bit. I think the groupby() approach is most suitable for my need. Thanks all, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From python at dylanreinhardt.com Thu Apr 17 01:37:30 2008 From: python at dylanreinhardt.com (Dylan Reinhardt) Date: Wed, 16 Apr 2008 16:37:30 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> Message-ID: <4c645a720804161637q4734b016ueddbef931fdd021f@mail.gmail.com> On Wed, Apr 16, 2008 at 3:23 PM, Rich Shepard wrote: > While all the examples print the > right side item of each tuple, I need to interate through those for each > left side item. Take another look at the second block I sent: for key in grouper.keys(): print key for value in grouper[key]: print '\t%s' % value If you want to ensure you iterate over the keys in a particular order, you could update that with: for key in set([i[0] for i in my_tuple]): print key for value in grouper[key]: print '\t%s' % value In what way is that not what you're looking for? From kirby.urner at gmail.com Thu Apr 17 01:37:42 2008 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 16 Apr 2008 16:37:42 -0700 Subject: [portland] BarCamp Portland: May 2nd-4th @ CubeSpace In-Reply-To: <480689AC.9090201@discorporate.us> References: <48067F14.6010700@discorporate.us> <480689AC.9090201@discorporate.us> Message-ID: duh, ok thx. Added my presenting about J idea. Actually teaching Python for big bucks that Saturday for my Academy, so should be hot to trot. Kirby On Wed, Apr 16, 2008 at 4:20 PM, jason kirtland wrote: > It's hiding there on the bottom left (after clicking "edit page"). > > > > kirby urner wrote: > > What's the process for editing the Wiki (invite key?). I was going > > to say maybe could present on J language, since exotic languages > > might get focus. > > > > Kirby > > From rshepard at appl-ecosys.com Thu Apr 17 01:45:36 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Apr 2008 16:45:36 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <4c645a720804161637q4734b016ueddbef931fdd021f@mail.gmail.com> References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> <4c645a720804161637q4734b016ueddbef931fdd021f@mail.gmail.com> Message-ID: On Wed, 16 Apr 2008, Dylan Reinhardt wrote: > Take another look at the second block I sent: > > for key in grouper.keys(): > print key > for value in grouper[key]: > print '\t%s' % value > > If you want to ensure you iterate over the keys in a particular order, > you could update that with: > > for key in set([i[0] for i in my_tuple]): > print key > for value in grouper[key]: > print '\t%s' % value > > In what way is that not what you're looking for? Either will work, Dylan. I was working my way through the responses and hadn't gotten to that one yet. 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 Thu Apr 17 01:49:05 2008 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 16 Apr 2008 16:49:05 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: On Wed, Apr 16, 2008 at 4:24 PM, Rich Shepard wrote: > On Wed, 16 Apr 2008, kirby urner wrote: > > >>>> thekeys = set([i for (i,j) in mydata]) > > I thought this more elegant, but when I could not use the 'j' values > associated with each 'i' value I did some reading on sets. They are > iterable, but not indexable. And I need to access each 'j' associated with > each 'i'. > Yeah, was just using the set to garner / harvest unique keys (throwing away j values, keeping only i values), then in the next loop building a data structure with filtration. Here'd be a complete program, data set of my own invention: IDLE 1.2.1 >>> thedata = [('salmon',1),('tuna',1),('salmon',3),('rockfish',4),('salmon',2), ('rockfish',2),('tuna',9),('barracuda',4),('trout',1),('barracuda',18)] def groupstuff(anydata): thekeys = set([i for (i,j) in anydata]) # get unique i values grouped = {} # return a dictionary listing j values, indexed by i values for key in thekeys: grouped[key] = [ j for (i,j) in anydata if i == key ] # scoop out j values return grouped >>> groupstuff(thedata) {'salmon': [1, 3, 2], 'tuna': [1, 9], 'barracuda': [4, 18], 'rockfish': [4, 2], 'trout': [1]} def graphit(groups): for key in groups.keys(): # loop through indexes print key for graph in sorted(groups[key]): # assume ordering of j-values matters print graph >>> graphit(groupstuff(thedata)) salmon 1 2 3 tuna 1 9 barracuda 4 18 rockfish 2 4 trout 1 > But, I learned quite a bit. I think the groupby() approach is most > suitable for my need. > > Thanks all, > > > > Rich From kirby.urner at gmail.com Thu Apr 17 03:09:27 2008 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 16 Apr 2008 18:09:27 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: On Wed, Apr 16, 2008 at 4:49 PM, kirby urner wrote: > On Wed, Apr 16, 2008 at 4:24 PM, Rich Shepard wrote: > def graphit(groups): > for key in groups.keys(): # loop through indexes PS: per David Goodger's "idiomatic Python" at OSCON last year, it'd be preferable to just go: def graphit(groups): for key in groups: # loop through indexes etc. i.e. as iterables, dictionaries already have a default "step though" behavior, which is to go through the keys. So you don't have to explicitly fire the keys() method, and doing so is less generic i.e. takes advantage of this being a dictionary, versus an iterable. Better to keep the semantics streamlined and go for the generic form over the special case -- more readable, smoother, whatever (I agreed with David's thesis). Kirby From python at dylanreinhardt.com Thu Apr 17 07:35:26 2008 From: python at dylanreinhardt.com (Dylan Reinhardt) Date: Wed, 16 Apr 2008 22:35:26 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: Message-ID: <4c645a720804162235k61c1dd6ap6244bef6cee2fa62@mail.gmail.com> On Wed, Apr 16, 2008 at 6:09 PM, kirby urner wrote: > i.e. as iterables, dictionaries already have a default "step though" > behavior, which is to go through the keys. > > So you don't have to explicitly fire the keys() method, and doing > so is less generic i.e. takes advantage of this being a dictionary, > versus an iterable. With all due respect to idiomatic Python, something important can be lost when you refine code. Treating all iterators the same is more general and more pleasing to the eye... but it is also less explicit and, therefore, less readable. Because iterables are ordinarily *ordered*, the risk here is that you may obscure the special *non-ordered* character of a key listing. Using .keys() might be ugly, but it is explicit and unsurprising. $.02, Dylan From rshepard at appl-ecosys.com Thu Apr 17 18:29:42 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Apr 2008 09:29:42 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> Message-ID: On Wed, 16 Apr 2008, Dylan Reinhardt wrote: >>>> grouper = {} >>>> for left, right in my_tuples: > ... grouper.setdefault(left, []).append(right) > > now you have a dict with values groped by keys, as shown below... > >>>> for key in grouper.keys(): > ... print key > ... for value in grouper[key]: > ... print '\t%s' % value > ... Dylan, Works perfectly for my report. I read in 'Python in a Nutshell' about the setdefault() method for dictionaries, but see nothing about extending that with .append(). Is this a short cut to adding the rightside values to each of the keys? Thanks for the lesson, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From python at dylanreinhardt.com Thu Apr 17 18:37:57 2008 From: python at dylanreinhardt.com (Dylan Reinhardt) Date: Thu, 17 Apr 2008 09:37:57 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> Message-ID: <4c645a720804170937n5a689398ne5f198d6e11a0dfa@mail.gmail.com> The setdefault method returns what the dictionary has at the specified key... but *sets* the value of that key first if no such key is found. Thus, for this expression... my_dict.setdefault(key, []) ...the return is always the list at my_dict[key] You can append to this because it's always a list. Hope that's helpful. Dylan On Thu, Apr 17, 2008 at 9:29 AM, Rich Shepard wrote: > On Wed, 16 Apr 2008, Dylan Reinhardt wrote: > > >>>> grouper = {} > >>>> for left, right in my_tuples: > > ... grouper.setdefault(left, []).append(right) > > > > now you have a dict with values groped by keys, as shown below... > > > >>>> for key in grouper.keys(): > > ... print key > > ... for value in grouper[key]: > > ... print '\t%s' % value > > ... > > Dylan, > > Works perfectly for my report. > > I read in 'Python in a Nutshell' about the setdefault() method for > dictionaries, but see nothing about extending that with .append(). Is this a > short cut to adding the rightside values to each of the keys? > > Thanks for the lesson, > > > > 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 rshepard at appl-ecosys.com Thu Apr 17 19:55:24 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Apr 2008 10:55:24 -0700 (PDT) Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <4c645a720804170937n5a689398ne5f198d6e11a0dfa@mail.gmail.com> References: <4c645a720804161348r510bde55p6a30dca6c3d9a322@mail.gmail.com> <4c645a720804170937n5a689398ne5f198d6e11a0dfa@mail.gmail.com> Message-ID: On Thu, 17 Apr 2008, Dylan Reinhardt wrote: > Hope that's helpful. Dylan, Yes it is. Confirms and clarifies my understanding. Thank you, 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 Mon Apr 21 23:54:13 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 21 Apr 2008 14:54:13 -0700 (PDT) Subject: [portland] Two Indices, One For Loop? Message-ID: I have a list of 12 labels and a variable number of rows, each with 12 attributes. I am writing a for loop to print out the label and value for each row (.tex output). Rather than writing (leaving out a lot of the file.write() code) for item in itemList: write(label[0]) write(item[0]) write(label[1]) write(item[1] ... is it possible to write something like: for i in labelList and for item in itemList: write(label[i]) write(item[i]) ? 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 Mon Apr 21 23:59:34 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 21 Apr 2008 14:59:34 -0700 (PDT) Subject: [portland] Two Indices, One For Loop? In-Reply-To: References: Message-ID: On Mon, 21 Apr 2008, Rich Shepard wrote: > for i in labelList and for item in itemList: > write(label[i]) > write(item[i]) That should be: write(labelList[i]) write(itemList(item[i]) 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 Tue Apr 22 00:07:05 2008 From: kirklin.mcdonald at gmail.com (Kirk McDonald) Date: Mon, 21 Apr 2008 15:07:05 -0700 Subject: [portland] Two Indices, One For Loop? In-Reply-To: References: Message-ID: <25bd58d10804211507t781ba80dna41394d540f24f95@mail.gmail.com> On Mon, Apr 21, 2008 at 2:59 PM, Rich Shepard wrote: > On Mon, 21 Apr 2008, Rich Shepard wrote: > > > > for i in labelList and for item in itemList: > > write(label[i]) > > write(item[i]) > > > > That should be: > > write(labelList[i]) > write(itemList(item[i]) > > > > Rich Why just use nested for loops? for item in itemList: for i in range(len(labelList)): write(labelList[i]) write(item[i]) --Kirk From mccredie at gmail.com Tue Apr 22 00:19:38 2008 From: mccredie at gmail.com (Matt McCredie) Date: Mon, 21 Apr 2008 15:19:38 -0700 Subject: [portland] Two Indices, One For Loop? In-Reply-To: References: Message-ID: <9e95df10804211519w228e0f03vbd482385a2c49fba@mail.gmail.com> > > for i in labelList and for item in itemList: > > write(label[i]) > > write(item[i]) > > > > That should be: > > write(labelList[i]) > write(itemList(item[i]) > > > > Rich It's not clear to me what labelList and itemList look like. I'm assuming something like this: labelList = ["label_0","label_1","label_2","label_3","label_4","label_5","label_6","label_7","label_8","label_9","label_10","label_11"] itemList = [ [ row0_item0, row0_item1, row0_item2, row0_item3, row0_item4, row0_item5, row0_item6, row0_item7, row0_item8, row0_item9, row0_item10, row0_item11,], [ row1_item0, row1_item1, ...], .... ] If that is the case, you can do something like this: for row in itemList: for label, item in zip(labelList, row): write(label) write(item) write("\n") Matt From rshepard at appl-ecosys.com Tue Apr 22 00:24:30 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 21 Apr 2008 15:24:30 -0700 (PDT) Subject: [portland] Two Indices, One For Loop? In-Reply-To: <9e95df10804211519w228e0f03vbd482385a2c49fba@mail.gmail.com> References: <9e95df10804211519w228e0f03vbd482385a2c49fba@mail.gmail.com> Message-ID: On Mon, 21 Apr 2008, Matt McCredie wrote: > It's not clear to me what labelList and itemList look like. I'm assuming > something like this: > > labelList = ["label_0","label_1","label_2","label_3","label_4","label_5","label_6","label_7","label_8","label_9","label_10","label_11"] > itemList = [ > [ row0_item0, row0_item1, row0_item2, row0_item3, row0_item4, > row0_item5, row0_item6, row0_item7, row0_item8, row0_item9, > row0_item10, row0_item11,], > [ row1_item0, row1_item1, ...], > .... > ] > > If that is the case, you can do something like this: That's the case, Matt. > for row in itemList: > for label, item in zip(labelList, row): > write(label) > write(item) > write("\n") That's essentially the same as regular nested for loops. Does it have specific advantages? Many 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 Tue Apr 22 00:09:50 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 21 Apr 2008 15:09:50 -0700 (PDT) Subject: [portland] Two Indices, One For Loop? In-Reply-To: <25bd58d10804211507t781ba80dna41394d540f24f95@mail.gmail.com> References: <25bd58d10804211507t781ba80dna41394d540f24f95@mail.gmail.com> Message-ID: On Mon, 21 Apr 2008, Kirk McDonald wrote: > Why just use nested for loops? > > for item in itemList: > for i in range(len(labelList)): > write(labelList[i]) > write(item[i]) That works. I thought there might be a more direct way. Thanks, Kirk, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From mccredie at gmail.com Tue Apr 22 00:43:17 2008 From: mccredie at gmail.com (Matt McCredie) Date: Mon, 21 Apr 2008 15:43:17 -0700 Subject: [portland] Two Indices, One For Loop? In-Reply-To: References: <9e95df10804211519w228e0f03vbd482385a2c49fba@mail.gmail.com> Message-ID: <9e95df10804211543m20e32545m42eb75524b433a88@mail.gmail.com> On Mon, Apr 21, 2008 at 3:24 PM, Rich Shepard wrote: > On Mon, 21 Apr 2008, Matt McCredie wrote: > > > > It's not clear to me what labelList and itemList look like. I'm assuming > > something like this: > > > > labelList = > ["label_0","label_1","label_2","label_3","label_4","label_5","label_6","label_7","label_8","label_9","label_10","label_11"] > > itemList = [ > > [ row0_item0, row0_item1, row0_item2, row0_item3, row0_item4, > > row0_item5, row0_item6, row0_item7, row0_item8, row0_item9, > > row0_item10, row0_item11,], > > [ row1_item0, row1_item1, ...], > > .... > > ] > > > > If that is the case, you can do something like this: > > > > That's the case, Matt. > > > > > for row in itemList: > > for label, item in zip(labelList, row): > > write(label) > > write(item) > > write("\n") > > > > That's essentially the same as regular nested for loops. Does it have > specific advantages? > > Many thanks, > > > > Rich It doesn't use indecies so it would work even if you were using say generator instead of lists or tuples. It is probably a _tiny_ bit faster too, but I'm sure that isn't a concern. In general, I avoid indecies if I can. Rarely should you need to call range(len(seq)), or anything similar in python. Matt From kirby.urner at gmail.com Tue Apr 22 02:00:54 2008 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 21 Apr 2008 17:00:54 -0700 Subject: [portland] Still Having List/Tuple Problems In-Reply-To: <4c645a720804162235k61c1dd6ap6244bef6cee2fa62@mail.gmail.com> References: <4c645a720804162235k61c1dd6ap6244bef6cee2fa62@mail.gmail.com> Message-ID: Interesting discussion, just flagged it for additional feedback on edu-sig here: http://mail.python.org/pipermail/edu-sig/2008-April/008515.html Kirby On Wed, Apr 16, 2008 at 10:35 PM, Dylan Reinhardt wrote: > On Wed, Apr 16, 2008 at 6:09 PM, kirby urner wrote: > > i.e. as iterables, dictionaries already have a default "step though" > > behavior, which is to go through the keys. > > > > So you don't have to explicitly fire the keys() method, and doing > > so is less generic i.e. takes advantage of this being a dictionary, > > versus an iterable. > > With all due respect to idiomatic Python, something important can be > lost when you refine code. Treating all iterators the same is more > general and more pleasing to the eye... but it is also less explicit > and, therefore, less readable. > > Because iterables are ordinarily *ordered*, the risk here is that you > may obscure the special *non-ordered* character of a key listing. > Using .keys() might be ugly, but it is explicit and unsurprising. > > $.02, > > Dylan > > > _______________________________________________ > Portland mailing list > Portland at python.org > http://mail.python.org/mailman/listinfo/portland > From rshepard at appl-ecosys.com Tue Apr 22 02:02:00 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 21 Apr 2008 17:02:00 -0700 (PDT) Subject: [portland] Two Indices, One For Loop? In-Reply-To: <9e95df10804211543m20e32545m42eb75524b433a88@mail.gmail.com> References: <9e95df10804211519w228e0f03vbd482385a2c49fba@mail.gmail.com> <9e95df10804211543m20e32545m42eb75524b433a88@mail.gmail.com> Message-ID: On Mon, 21 Apr 2008, Matt McCredie wrote: > It doesn't use indecies so it would work even if you were using say > generator instead of lists or tuples. It is probably a _tiny_ bit faster > too, but I'm sure that isn't a concern. In general, I avoid indecies if I > can. Rarely should you need to call range(len(seq)), or anything similar > in python. Matt, Thank you for the lesson. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From python at dylanreinhardt.com Tue Apr 22 02:50:11 2008 From: python at dylanreinhardt.com (Dylan Reinhardt) Date: Mon, 21 Apr 2008 17:50:11 -0700 Subject: [portland] Two Indices, One For Loop? In-Reply-To: References: <25bd58d10804211507t781ba80dna41394d540f24f95@mail.gmail.com> Message-ID: <4c645a720804211750w5b710686ycf49707dea0245cc@mail.gmail.com> On Mon, Apr 21, 2008 at 3:09 PM, Rich Shepard wrote: > That works. I thought there might be a more direct way. I don't know if it's more direct or not... but if you don't like zip, you could pair up labels and items with a list comprehension: for label, item in [(labels[i], items[i]) for i in range(len(labels))]: print label print item This would only work if you can assume that there are at least as many items as labels. FWIW... Dylan From rshepard at appl-ecosys.com Wed Apr 23 18:54:37 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 23 Apr 2008 09:54:37 -0700 (PDT) Subject: [portland] Locating Cause of SegFault Message-ID: There's a function in my model that's supposed to loop 114 times. It loops twice, then seg faults. No other error message is displayed. Please suggest a strategy to isolate the cause of the seg fault. 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 Wed Apr 23 22:23:31 2008 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 23 Apr 2008 13:23:31 -0700 (PDT) Subject: [portland] Locating Cause of SegFault In-Reply-To: <17588.134.134.136.35.1208980624.squirrel@email.powweb.com> References: <17588.134.134.136.35.1208980624.squirrel@email.powweb.com> Message-ID: On Wed, 23 Apr 2008, markgross at thegnar.org wrote: > run in ipython with pdb enabled? Mark, I've been busy fixing the issues and didn't remove the need for another response. I copied the offending code to another file, put in some data, and found a data error and a couple of typos in the code. Fixed those and solved the problem. Thanks very much, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation Voice: 503-667-4517 Fax: 503-667-8863 From markgross at thegnar.org Wed Apr 23 21:57:04 2008 From: markgross at thegnar.org (markgross at thegnar.org) Date: Wed, 23 Apr 2008 15:57:04 -0400 (EDT) Subject: [portland] Locating Cause of SegFault In-Reply-To: References: Message-ID: <17588.134.134.136.35.1208980624.squirrel@email.powweb.com> > There's a function in my model that's supposed to loop 114 times. It > loops > twice, then seg faults. No other error message is displayed. Please > suggest > a strategy to isolate the cause of the seg fault. > run in ipython with pdb enabled? or try ulimit core unmlimited and then load the core file from gdb good luck. --mgross > Thanks, > > 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 >