如何从python脚本中获取终端的编码? [英] How do you get the encoding of the terminal from within a python script?
本文介绍了如何从python脚本中获取终端的编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
python myscript一些参数
我明白,字符串 sys.argv [1]
和 sys.argv [2]
将在终端中指定编码。有没有办法从python脚本中获取这些信息?
我的目标是这样的:
terminal_enocding = some_way.to.GET_TERMINAL_ENCODING
some =`sys.argv [1]`.decode(terminal_encoding)
arguments =`sys.argv [2] .decode(terminal_encoding)
解决方案
sys.stdout.encoding
将为您提供标准输出的编码。 sys.stdin.encoding
将为您提供标准输入的输入。
Let's say you want to start a python script with some parameters like
python myscript some arguments
I understand, that the strings sys.argv[1]
and sys.argv[2]
will have the encoding specified in the terminal. Is there a way to get this information from within the python script?
My goal is something like this:
terminal_enocding = some_way.to.GET_TERMINAL_ENCODING
some = `sys.argv[1]`.decode(terminal_encoding)
arguments = `sys.argv[2]`.decode(terminal_encoding)
解决方案
sys.stdout.encoding
will give you the encoding of standard output. sys.stdin.encoding
will give you the encdoing for standard input.
这篇关于如何从python脚本中获取终端的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文