Topic on Manual talk:Pywikibot/listpages.py

David.Mirth (talkcontribs)

Sorry for a stupid question, but how do I export the list into a .txt file?

Octahedron80 (talkcontribs)

Append your command with

> somefile.txt

This is common syntax to export output buffer to a file.

Vladis13 (talkcontribs)

This works in Linux, but not in Windows.

Octahedron80 (talkcontribs)

Windows works too. Try it.

Vladis13 (talkcontribs)
Octahedron80 (talkcontribs)
Vladis13 (talkcontribs)
> python pwb.py listpages -start:s -limit:5 > file.txt
<Unicode redirected stdout>.write: TypeError('write() argument must be str, not bytes',)
Traceback (most recent call last):
  File "pwb.py", line 270, in <module>
    if not main():
  File "pwb.py", line 264, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 109, in run_python_file
    main_mod.__dict__)
  File ".\scripts\listpages.py", line 240, in <module>
    main()
  File ".\scripts\listpages.py", line 223, in main
    pywikibot.stdout(page_fmt.output(num=i, fmt=fmt))
  File "c:\pwb\pywikibot\bot.py", line 473, in stdout
    logoutput(text, decoder, newline, STDOUT, **kwargs)
  File "c:\pwb\pywikibot\bot.py", line 438, in logoutput
    logger.log(_level, text, extra=context, **kwargs)
  File "c:\python35\lib\logging\__init__.py", line 1345, in log
    self._log(level, msg, args, **kwargs)
  File "c:\python35\lib\logging\__init__.py", line 1415, in _log
    self.handle(record)
  File "c:\python35\lib\logging\__init__.py", line 1425, in handle
    self.callHandlers(record)
  File "c:\python35\lib\logging\__init__.py", line 1487, in callHandlers
    hdlr.handle(record)
  File "c:\python35\lib\logging\__init__.py", line 855, in handle
    self.emit(record)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 503, in emit
    return self.UI.output(text, targetStream=self.stream)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 194, in output
    self._print(text, targetStream)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 137, in _print
    self.printNonColorized(text, targetStream)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 129, in printNonColorized
    targetStream.write(line)
  File "c:\pwb\pywikibot\userinterfaces\win32_unicode.py", line 254, in write
    self._stream.write(text)
TypeError: write() argument must be str, not bytes
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort
Octahedron80 (talkcontribs)

^ It was going to work. I think you have issue with Unicode instead. 😅

David.Mirth (talkcontribs)

I have the same problem as mentioned above, I thought I am doing sth wrong... The problem is probably in Unicode or something, a friend of mine discusses this in a python forum, we'll se :)

Vladis13 (talkcontribs)

I tried change codepage of console via 'chcp 65001' and 'chcp 1252'. The console, the script, and script out is good understand utf-8. (Like python pwb.py listpages -subcatsr:"Категория:Родившиеся в IX веке".) Python good open|write file|console on utf-8. The error is only when python redirect stdout to file in Windows.

Reply to "Output"