On 08/03/2011 03:01, Tycho Andersen wrote:
Consider the following session:

Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import re
p = re.compile("foo")
re.sub(p, "bar", "foobaz", flags=re.IGNORECASE)
Traceback (most recent call last):
   File "<stdin>", line 1, in<module>
TypeError: sub() got an unexpected keyword argument 'flags'

The flags should really be passed to re.compile() instead. However,
the documentation indicates that they can be passed to re.sub() as
well. Is this a bug, or am I reading things wrong?

http://docs.python.org/library/re.html#re.sub

You didn't read far enough. It says at the end of that entry:

   """Changed in version 2.7: Added the optional flags argument."""

You're on version 2.6.

Another point: even in version 2.7 it won't let you provide flags if
you pass in a compiled regex.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to