homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger
Date 2013年01月30日.23:53:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1359589982.45.0.929656950631.issue17087@psf.upfronthosting.co.za>
In-reply-to
Content
Experience teaching Python has shown that people have a hard time learning to work with match objects. A contributing cause is the opaque repr:
 >>> import re
 >>> s = 'On 3/14/2013, Python celebrate Pi day.'
 >>> mo = re.search(r'\d+/\d+/\d+', s)
 >>> mo
 <_sre.SRE_Match object at 0x100456100>
They could explore the match object with dir() and help() and the matchobject methods and attributes:
 >>> dir(mo)
 ['__class__', '__copy__', '__deepcopy__', ...
 'end', 'endpos', 'expand', 'group', ... ]
 
 >>> mo.start()
 3
 >>> mo.end()
 12
 >>> mo.group(0)
 '3/14/2013'
However, this gets old when experimenting with alternative regular expressions. A better solution is to improve the repr:
 >>> re.search(r'\d+/\d+/\d+', s)
 <SRE Match object: start=3, stop=12, group(0)='3/14/2013'>
This would make the regular expression module much easier to work with.
History
Date User Action Args
2013年01月30日 23:53:02rhettingersetrecipients: + rhettinger
2013年01月30日 23:53:02rhettingersetmessageid: <1359589982.45.0.929656950631.issue17087@psf.upfronthosting.co.za>
2013年01月30日 23:53:02rhettingerlinkissue17087 messages
2013年01月30日 23:53:02rhettingercreate

AltStyle によって変換されたページ (->オリジナル) /