[Tutor] Bundle help!

Jason Massey jason.massey at gmail.com
Mon Jul 16 15:05:11 CEST 2007


A nice tutorial on using regular expressions in Python:

http://www.amk.ca/python/howto/regex/



On 7/15/07, bhaaluu <bhaaluu at gmail.com> wrote:
>
> Hi!
>
> http://docs.python.org/lib/module-re.html
>
> Regular Expressions module.
>
> On 7/15/07, Sara Johnson <sarliz73 at yahoo.com> wrote:
> > ========================
> >
> > Just curious, but in this link ('
> > http://xahlee.org/perl-python/sort_list.html ') you
> > mentioned, what does the "re" part mean?  At first I thought it was the
> name
> > of the list or 'return' but that's included later.
> >
> >
> > ***************
> >
> > def myComp (x,y):
> >     import re
> >     def getNum(str): return float(re.findall(r'\d+',str)[0])
> >     return cmp(getNum(x),getNum(y))
> >
> > li.sort(myComp)
> > print li # returns ['web7-s.jpg', 'my23i.jpg', 'fris88large.jpg',
> > 'my283.jpg']
> >
> > Thanks,
> > Sara
>
> Someone recently showed this to me:
>
> $ python
>
> >>> import re
>
> >>> dir(re)
>
> ['DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', 'S',
> 'U', 'UNICODE',
> 'VERBOSE', 'X', '__all__', '__builtins__', '__doc__', '__file__',
> '__name__', 'compile',
> 'engine', 'error', 'escape', 'findall', 'finditer', 'match', 'purge',
> 'search', 'split', 'sub',
> 'subn', 'template']
>
> >>> dir(re.match)
>
> ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__',
> '__getattribute__', '__hash__', '__init__', '__module__', '__name__',
> '__new__',
> '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
> 'func_closure',
> 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals',
> 'func_name']
>
> All those quoted things that the dir() function spit out are in the
> module.
>
> >>> dir(re.match.__doc__)
>
> 'Try to apply the pattern at the start of the string, returning\n
> a match object, or None if no match was found.'
>
> You can find all sorts of stuff like this. It's somewhat cryptic at first,
> but with the above documentation in hand, you can figure it out
> eventually. =)
>
> --
> bhaaluu at gmail dot com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070716/fce07243/attachment.htm 


More information about the Tutor mailing list