It works! Thank you. 2013/7/22 <[email protected]>
> > > > ----- Original Nachricht ---- > Von: Bináris <[email protected]> > An: Pywikipedia discussion list <[email protected]> > 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 > -- Bináris
_______________________________________________ Pywikipedia-l mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
