redemo.py with named groups

moriwaka moriwaka at gmail.com
Mon Aug 21 04:24:15 EDT 2006


Hi,
I wrote an easy patch for redemo.py to print named groups.

For example,

regexp: (?P<spam>.*)
string: foobar

shows following groups.

Groups:
0: 'foobar'
1: 'foobar'
'spam': 'foobar'

I don't know how/where to commit this patch..
any suggestions?

--- Tools/scripts/redemo.py   2004-02-13 02:35:32.000000000 +0900
+++ redemo.py   2006-08-21 01:11:11.000000000 +0900
@@ -148,6 +148,10 @@
                 for i in range(len(groups)):
                     g = "%2d: %r" % (i, groups[i])
                     self.grouplist.insert(END, g)
+                groupdict = m.groupdict()
+                for key in groupdict:
+                    g = "%r: %r"  % (key, groupdict[key])
+                    self.grouplist.insert(END, g)
             nmatches = nmatches + 1
             if self.showvar.get() == "first":
                 break




More information about the Python-list mailing list