Small suggestion, regular expressions
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
Am 12.07.2010 08:12, schrieb Ben Fisher:
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.
Hi Ben, thanks for the suggestion, that is indeed the better way to write these regexes. Should be corrected now and will be online soon. regards, Georg
participants (2)
-
Ben Fisher -
Georg Brandl