Topic on Manual talk:Pywikibot/

Jump to navigation Jump to search
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 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 "", line 270, in <module>
    if not main():
  File "", line 264, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "", line 109, in run_python_file
  File ".\scripts\", line 240, in <module>
  File ".\scripts\", line 223, in main
    pywikibot.stdout(page_fmt.output(num=i, fmt=fmt))
  File "c:\pwb\pywikibot\", line 473, in stdout
    logoutput(text, decoder, newline, STDOUT, **kwargs)
  File "c:\pwb\pywikibot\", line 438, in logoutput
    logger.log(_level, text, extra=context, **kwargs)
  File "c:\python35\lib\logging\", line 1345, in log
    self._log(level, msg, args, **kwargs)
  File "c:\python35\lib\logging\", line 1415, in _log
  File "c:\python35\lib\logging\", line 1425, in handle
  File "c:\python35\lib\logging\", line 1487, in callHandlers
  File "c:\python35\lib\logging\", line 855, in handle
  File "c:\pwb\pywikibot\userinterfaces\", line 503, in emit
    return self.UI.output(text,
  File "c:\pwb\pywikibot\userinterfaces\", line 194, in output
    self._print(text, targetStream)
  File "c:\pwb\pywikibot\userinterfaces\", line 137, in _print
    self.printNonColorized(text, targetStream)
  File "c:\pwb\pywikibot\userinterfaces\", line 129, in printNonColorized
  File "c:\pwb\pywikibot\userinterfaces\", line 254, in write
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 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"