Reputation: 1479
I have a Python file that does some processing to words in a text file and prints them out to standard output. When it prints to standard output, the format is ASCII. However, when I try to write it to a file like this: python stem.py > output.txt
the output.txt file contains only characters that look like this:
^@c^@r^@a^@n^@f^@i^@e^@l^@d^@0^@2^@8^@1ptblustr^@^@^@.^@u^@s^@e^
How should I resolve this?
Upvotes: 1
Views: 205
Reputation: 7558
Look at this post.. "Python sets stdout's encoding when writing to a console but not when writing to a file. " Redirecting python's stdout to the file fails with UnicodeEncodeError
That may be the source of your problem though you say the output is ascii. What version of python are you using? (strings in Python3 are unicode). And posting some code might help a bit :)
Upvotes: 1