當前位置:編程學習大全網 - 網站源碼 - 在geany中編譯python,怎樣才能輸出中文

在geany中編譯python,怎樣才能輸出中文

如果是Linux平臺,直接源碼文件頭上聲明:

#?-*-?coding:?utf-8?-*-

輸出的時候直接print就可以了.

print("中文")

如果是Windows平臺,需要加個前置hook函數來處理:

class?UnicodeStreamFilter:

def?__init__(self,?target):

self.target?=?target

self.encoding?=?'utf-8'

self.errors?=?'replace'

self.encode_to?=?self.target.encoding

def?write(self,?s):

if?type(s)?==?str:

s?=?s.decode("utf-8")

s?=?s.encode(self.encode_to,?self.errors).decode(self.encode_to)

self.target.write(s)

if?sys.stdout.encoding?==?'cp936':

sys.stdout?=?UnicodeStreamFilter(sys.stdout)

  • 上一篇:補碼10001源代碼。
  • 下一篇:紅黃藍線是什麽意思?
  • copyright 2024編程學習大全網