class NullWriter:

    def write(self, *args, **kwargs):
        pass
if len(sys.argv) == 2:
    if sys.argv[1] == '1':
        sys.stderr = NullWriter()
elif sys.argv[1] == '2':
    sys.stderr = codecs.getwriter('utf8')(sys.stderr)
print('\u20ac', file=sys.stderr)
print('ok')
Default encoding for python for stderr?