----- Original Nachricht ---- Von: Bináris wikiposta@gmail.com An: Pywikipedia discussion list pywikipedia-l@lists.wikimedia.org Datum: 21.07.2013 18:14 Betreff: [Pywikipedia-l] Additional parameter in a replace function
Hi,
I use functions in my fixes.py as written in https://hu.wikipedia.org/wiki/Szerkeszt%C5%91:Bin%C3%A1ris/Fixes_and_functio ns_HOWTO .
Now, my idea is to use an additional parameter. (In case nobody breaks the framework. :-)) So my fix has something like this in replacements:
(ur'someregex', MyFunc), Then MyFunc takes the match object as a parameter and is executed. I have to write def MyFunc(match): etc.
Now I want to write def MyFunc(match, mode), but I can't pass mode to MyFunc anyway. I guessed the line in question is #195 in textlib.py: replacement = new(match)
Here I stopped. How could I pass additional optional parameters?
Just an idea, I haven't investigated in it but you could try it out: you may use a class instance inside fixes.py and pass the option through the constructor. Your MyFunc should be an instance method. e.g. class myClass(object):
def __init__(self, option): self.option = option
def myFunc(self, match): result = u'' # change the result depending of match and self.option # ... return result
thisClass = myClass(option='submit anything as option')
and play with replacements using thisClass.myFunc
Best xqt
This sounds very promising, I will try it!
It works! Thank you.
2013/7/22 info@gno.de
----- Original Nachricht ---- Von: Bináris wikiposta@gmail.com An: Pywikipedia discussion list pywikipedia-l@lists.wikimedia.org Datum: 21.07.2013 18:14 Betreff: [Pywikipedia-l] Additional parameter in a replace function
Hi,
I use functions in my fixes.py as written in
https://hu.wikipedia.org/wiki/Szerkeszt%C5%91:Bin%C3%A1ris/Fixes_and_functio
ns_HOWTO .
Now, my idea is to use an additional parameter. (In case nobody breaks
the
framework. :-)) So my fix has something like this in replacements:
(ur'someregex', MyFunc), Then MyFunc takes the match object as a parameter and is executed. I have to write def MyFunc(match): etc.
Now I want to write def MyFunc(match, mode), but I can't pass mode to MyFunc anyway. I guessed the line in question is #195 in textlib.py: replacement = new(match)
Here I stopped. How could I pass additional optional parameters?
Just an idea, I haven't investigated in it but you could try it out: you may use a class instance inside fixes.py and pass the option through the constructor. Your MyFunc should be an instance method. e.g. class myClass(object):
def __init__(self, option): self.option = option def myFunc(self, match): result = u'' # change the result depending of match and self.option # ... return result
thisClass = myClass(option='submit anything as option')
and play with replacements using thisClass.myFunc
Best xqt