Re: [Tutor] class methods: using class vars as args?

2010-05-23 Thread Matthew Wood
Hey Alex, What's happening is that you're still in "defining functions" mode on the line def doSomething(self, arg3=self.arg1): self, which is really nothing more than a parameter being passed in (special parameter, but a parameter none the less) hasn't been assigned a value yet. Imagine this f

Re: [Tutor] requesting a help

2010-05-23 Thread Matthew Wood
I'd start with something like this: final_result = [] for data, target in zip(f, t): a, b = [elem.strip() for elem in line.split()] c = target.strip() final_result.append([[a, b], [c]]) Though I'm not sure why you have the "result" data in single element lists. -- I enjoy haiku but s

Re: [Tutor] PYTHON 3.1

2010-05-24 Thread Matthew Wood
Well, I'd use the raw_input function instead of the input function. and I'd check out the math.floor function as well. :-) Lemme know if you have any other questions. -- I enjoy haiku but sometimes they don't make sense; refrigerator? On Mon, May 24, 2010 at 1:55 AM, Dipo Elegbede wrote: >

Re: [Tutor] PYTHON 3.1

2010-05-24 Thread Matthew Wood
On Mon, May 24, 2010 at 3:36 AM, C M Caine wrote: > On 24 May 2010 09:20, Matthew Wood wrote: > > Well, I'd use the raw_input function instead of the input function. > > > > and I'd check out the math.floor function as well. :-) > > > > Lemme know if you

Re: [Tutor] circular looping

2010-05-24 Thread Matthew Wood
This is a GREAT application for generators! def cycle(seq, index): l = len(seq) for i in range(len(seq)): cursor = (i + index) % l yield seq[cursor] Then you just pass it the starting index you want, and all is well in the world. :-) Also, gratuitous use of the enumerate

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
#!/usr/bin/env python Here's my best attempt.  I'm not sure if it's "simpler" than yours, but for me it seems a bit cleaner.  Then again, I LOVE the zip operator, and the '*' operator too.  :-)  Whenever I see a "transpose this" type problem, I think zip. y = {'a': [1, 2, 3], 'c': [7, 8, 9], 'b

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
Well, that makes a lot of sense. I probably should have looked it up. :-) That said, the version with an extra line will work on python < 2.6, so I'd probably just leave it that way. But thanks the docs pointer. Always useful. That said, if I KNEW that my software was only to be implemented

Re: [Tutor] Speed it up...

2010-05-27 Thread Matthew Wood
On Thu, May 27, 2010 at 3:37 AM, trias wrote: > > Hi, > >  I have wrote the following lines that work fine, but are quite slow, are > there any obvious things I can consider to speed things up? > >  Thanks > > import MySQLdb > > import scipy > > import csv > > dbtest=MySQLdb.connect(host="***",use

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Matthew Wood
Wow. Something horrible happened here. http://xkcd.com/386/ I THOUGHT the guaranteed same-ordering of dict.keys and dict.values started in python 2.6. That was a simple mistake. It turns out, that's not the case. But in general, access to dicts and sets is unordered, so you can't/don't/shoul

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-29 Thread Matthew Wood
On Fri, May 28, 2010 at 6:55 PM, Steven D'Aprano wrote: > On Fri, 28 May 2010 12:00:46 pm Matthew Wood wrote: > > > I THOUGHT the guaranteed same-ordering of dict.keys and dict.values > > started in python 2.6. That was a simple mistake. > > > > It turns out, t

Re: [Tutor] namespaces

2010-05-30 Thread Matthew Wood
That's probably my least favorite error message in python. I wish that somehow it would have the line number of the first assignment statement instead of the first read statement. I know why it's not that way, but I just wish it weren't. -- I enjoy haiku but sometimes they don't make sense; ref

Re: [Tutor] treeTraversal, nested return?

2010-06-04 Thread Matthew Wood
In general, there's 2 solutions to your "unflattening" problem. A) The general solution: Keep track of the depth you're at, and add tabs/spaces ('\t' * depth) as necessary. B) The xml solution: Use (for example) the dom.minidom module, and create a new "ul node" and populate it with children, at

Re: [Tutor] treeTraversal, nested return?

2010-06-05 Thread Matthew Wood
st and most graphic example would be a nested list of lists, but > for the life of me I can't work out how to generate that in this context. > > Jon > > > > On Fri, 4 Jun 2010, Matthew Wood wrote: > > In general, there's 2 solutions to your "unflattening&q

Re: [Tutor] Regular expression grouping insert thingy

2010-06-08 Thread Matthew Wood
re.sub(r'(\d+)x', r'\1*x', input_text) -- I enjoy haiku but sometimes they don't make sense; refrigerator? On Tue, Jun 8, 2010 at 10:11 PM, Lang Hurst wrote: > This is so trivial (or should be), but I can't figure it out. > > I'm trying to do what in vim is > > :s/\([0-9]\)x/\1*x/ > > That is

[Tutor] Fwd: treeTraversal, nested return?

2010-06-09 Thread Matthew Wood
Gah, hit the reply button instead of reply-all. :-( -- I enjoy haiku but sometimes they don't make sense; refrigerator? -- Forwarded message -- From: Matthew Wood Date: Wed, Jun 9, 2010 at 2:30 PM Subject: Re: [Tutor] treeTraversal, nested return? To: jjcr...@uw.edu