Hi I have the following python file 'test.py':
import sys
print(sys.stdout.encoding)
sys.stdout.reconfigure(encoding='utf-8')
print(sys.stdout.encoding)
when I run
py test.py
I get:
utf-8
utf-8
but when I run
py test.py > test.txt
or
py test.py | Out-File -FilePath test.txt -Encoding ASCII
I get from test.txt:
cp1252
utf-8
Update: when I run following python code:
import sys, locale
print(sys.getdefaultencoding())
print(locale.getpreferredencoding())
I get:
utf-8
cp1252
Question:
May I know why this happen and what should I do so that the default encoding is utf-8 when redirecting?
Thanks