2011/6/28 Morten Wang nettrom@gmail.com
2: Using functions instead of strings as the replacement in sub(). If you're looking to do a fair amount of conditional logic in your replacement, it might be more easily written by having a function do it, rather than attempt to do it all with a regex.
My $.02.
Thank you for this great idea that is worth much more than $.02. :-) I can tell that my problem is completely solved now, much better than I had hoped previously. I am glad to announce this small guide to functions which is the result of my last two day's work: http://hu.wikipedia.org/wiki/Szerkeszt%C5%91:Bin%C3%A1ris/Fixes_and_function... This shows not only an example of a complicated replacement, but also the way to compare the match to the whole article (removing redundant links), or generating a long fix by means of a function. Another example is how to choose between two options for replacement during runtime (when you cannot decide it in coding time without a text environment).
On Sun, Jul 3, 2011 at 7:40 AM, Bináris wikiposta@gmail.com wrote:
Thank you for this great idea that is worth much more than $.02. :-) I can tell that my problem is completely solved now, much better than I had hoped previously. I am glad to announce this small guide to functions which is the result of my last two day's work:
http://hu.wikipedia.org/wiki/Szerkeszt%C5%91:Bin%C3%A1ris/Fixes_and_function... This shows not only an example of a complicated replacement, but also the way to compare the match to the whole article (removing redundant links), or generating a long fix by means of a function. Another example is how to choose between two options for replacement during runtime (when you cannot decide it in coding time without a text environment).
I'm happy to hear that this worked out, of course :) Thanks for taking the time to document it, you've created a really good resource that shows some of power available in the Pywikipediabot framework with some additional code, good job!
Cheers, Morten
I enhanced the tutorial with two more chapters: one about the lookaheads/lookbehinds (it is important because a varible width lookbehind is not allowed in a regex but sometimes necessary) and one about the use of lambda functions.
2011/7/3 Bináris wikiposta@gmail.com
I am glad to announce this small guide to functions which is the result of my last two day's work:
http://hu.wikipedia.org/wiki/Szerkeszt%C5%91:Bin%C3%A1ris/Fixes_and_function...