re.match versus re.findall

2006-02-09 Thread JerryB
Hi, I have a string like this: invalidStr = "192.168.*.1" I want to be sure I don't get a * followed by a number, i.e. I want invalidStr to be invalid. So I do: numberAfterStar = re.compile(r'\*.*\d') Now, here's the fun: If I run: if numberAfterStar.findall(invalidStr): print "Found it wi

Re: locals() and dictionaries

2006-02-01 Thread JerryB
Rocco: thanks for your response. The examples were just made up. I don't normally use 'dict' and 'str'. I know I can create a dictionary with the variables I want, etc. My question is not how to solve the problem, or how to come up with a work-around (I'm getting pretty good at this one :), so my q

locals() and dictionaries

2006-02-01 Thread JerryB
Hi, I have a dictionary, a string, and I'm creating another string, like this: dict = {} dict[beatles] = "need" str = "love" mystr = """All you %(dict[beatles])s is %(str)s""" % locals() Why do I get keyerror: 'dict[one]'? Is there a way to reference the elements in a dictionary with locals() o

Dictionary sorting problem

2005-09-16 Thread JerryB
Hi, I have a dictionary for counting ocurrences of strings in a document. The dictionary looks like this: 'hello':135 'goodbye':30 'lucy':4 'sky':55 'diamonds':239843 'yesterday':4 I want to print the dictionary so I see most common words first: 'diamonds':239843 'hello':135 'sky':55 'goodbye':3