Hi!
In replace.py, current version 8920, line 444: if not page.canBeEdited(): should change to if not self.articles and not page.canBeEdited(): The reason is that with the new -save/-savenew options (introduced in rev 8700) we may use replace.py for gathering titles, and that's what I am doing in the minute. I want to collect titles from* fr, es, de* Wikipedias rather than my home wiki, but they seem not to allow edits without botflag. I don't need a flag and I won't change anything there, only save titles from those wikis, but the current line 444 prevents me of doing that. self.articles is not None iff -save or -savenew option is used, which means we don't edit the wiki.
Another issue is with line 843, titlefile = codecs.open(filename, encoding='utf-8', mode=(lambda x: x and 'a' or 'w')(append)) I tested my original version which had an IF here as far as I remember, and you turned it to lambda function. But somehow the -save option behaves now just as -savenew does, i.e. overwrites the old file instead of appending. Could you please help?
----- Original Nachricht ---- Von: Bináris wikiposta@gmail.com An: Pywikipedia discussion list pywikipedia-l@lists.wikimedia.org Datum: 25.02.2011 15:16 Betreff: [Pywikipedia-l] Two minor problems in replace.py (attn xqt)
Hi!
In replace.py, current version 8920, line 444: if not page.canBeEdited(): should change to if not self.articles and not page.canBeEdited():
OK
wiki.
Another issue is with line 843, titlefile = codecs.open(filename, encoding='utf-8', mode=(lambda x: x and 'a' or 'w')(append)) I tested my original version which had an IF here as far as I remember, and you turned it to lambda function. But somehow the -save option behaves now just as -savenew does, i.e. overwrites the old file instead of appending. Could you please help?
I tried it in idle:
append = True (lambda x: x and 'a' or 'w')(append)
'a'
append = False (lambda x: x and 'a' or 'w')(append)
'w'
Greetings xqt
2011/2/25 info@gno.de
OK
Thanks a lot.
I tried it in idle:
Then I continue investigating it.
On 25 February 2011 15:49, info@gno.de wrote:
append = True (lambda x: x and 'a' or 'w')(append)
'a'
append = False (lambda x: x and 'a' or 'w')(append)
'w'
By the way, alternative options would be:
append = True append and 'a' or 'w'
'a'
append = False append and 'a' or 'w'
'w'
Of course, the
'a' if append else 'w'
is nicer, but has only been supported for python 2.5+.
An alternative, third, method, would be
append = True ['w', 'a'][append]
'a'
append = False ['w', 'a'][append]
'w'
No reason to change the working code, of course, but just possibilies to keep in mind.
Best regards, Merlijn
Thanks you both!
2011/2/25 Merlijn van Deen valhallasw@arctus.nl
Of course, the
'a' if append else 'w'
is nicer, but has only been supported for python 2.5+.
This is my personal favourite, and I really would be glad to see 2.4 in the museum (together with all 2.x :-D)
An alternative, third, method, would be
append = True ['w', 'a'][append]
'a'
This is great, I would never have thought of that myself! I learned something interesting today.
Another issue is with line 843, titlefile = codecs.open(filename, encoding='utf-8', mode=(lambda x: x and 'a' or 'w')(append)) I tested my original version which had an IF here as far as I remember, and you turned it to lambda function. But somehow the -save option behaves now just as -savenew does, i.e. overwrites the old file instead of appending. Could you please help?
The behaviour was reversed. I fixed it in r9011
xqt