[docs] Small suggestion, regular expressions

Ben Fisher jamon.ben at gmail.com
Mon Jul 12 08:12:28 CEST 2010


Hi,
I have a small suggestion in Python docs, Standard library, section 7.2 re.
One of the examples 7.2.6.6. currently reads
>>> text = "Professor Abdolmalek, please report your absences promptly."
>>> re.sub("(\w)(\w+)(\w)", repl, text)
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
>>> re.sub("(\w)(\w+)(\w)", repl, text)
'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.'

I would suggest that the string literals be instead written
>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.'
with the r in front, even though this doesn't change the code's behavior.
In this way it would correspond with 7.2.6.7. and is better practice
in my opinion.


By the way, thanks for including such helpful examples. Ever since I
learned Python I've appreciated the documentation.

-Ben


More information about the docs mailing list