Atom-script: Not support print chinese

Created on 15 Jan 2016  路  6Comments  路  Source: atom-community/atom-script

I have a python file like

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

print('娴嬭瘯')

and print like this

锟斤拷锟斤拷

Most helpful comment

@LD00000 I came across the same problem. For me, it looks like atom-script on Windows uses cp1252 (Windows 1252) encoding by default instead of utf-8 (the default encoding may depend on your locale and platform).

As a work-around you can specify the encoding as utf-8 in your code for the system out and error streams:

import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

print ('娴嬭瘯')

All 6 comments

what OS / Version of script are you using? works ok on OSX with 3.4.0, quick thing just to check, have a look at your file encoding settings for atom, playing with this and also changing the encoding on the bottom right of the editor caused some really weird behaviour for me.

OS: WIN10
script Version: 3.4.0
My atom file encoding setting and bottom right encoding are both utf-8
It works ok in windows cmd, but not work well in script

@LD00000 I came across the same problem. For me, it looks like atom-script on Windows uses cp1252 (Windows 1252) encoding by default instead of utf-8 (the default encoding may depend on your locale and platform).

As a work-around you can specify the encoding as utf-8 in your code for the system out and error streams:

import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

print ('娴嬭瘯')

so much thanks @dbolton

so much thanks @dbolton

I solved this problem by adding an environment varibale

PYTHONIOENCODING=utf-8

You can press Ctrl+Alt+Shift+O to add it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stwykd picture stwykd  路  6Comments

wookiist picture wookiist  路  3Comments

ghost picture ghost  路  5Comments

JohnnyUrosevic picture JohnnyUrosevic  路  5Comments

jaredleekatzman picture jaredleekatzman  路  3Comments