When the output contains Unicode like ä and ö, and redirecting output like python sample.py > output.txt
Traceback (most recent call last):
File "sample.py", line 44, in <module>
main()
File "sample.py", line 27, in main
sample(args)
File "sample.py", line 41, in sample
print(model.sample(sess, chars, vocab, args.n, args.prime, args.sample))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 31: ordinal not in range(128)
When the output contains Unicode like ä and ö, and redirecting output like
python sample.py > output.txt
So encode the output as UTF-8 instead.