python终端输出乱码怎么解决?
在命令行终端上工作时,经常会碰到一个头疼的问题就是中文乱码。下面我们就来看一下解决python在终端输出乱码的解决方法。
牵涉编码的地方一共有五处:
Python代码文件前两行声明的编码
Python代码文件实际存储所使用的编码
Vim的显示编码
Linux系统的文件编码
SecureCRT等终端设置的显示编码
严格来讲,五码一致的时候,如果文件没有损坏,应该是能够正常显示了。
Python编码声明:
如果python代码文件中包含中文,就一定要在代码文件的前两行(注意:一定要是前两行)做出编码声明,否则python代码默认采用ASCII保存,这样遇到中文字符就会报错。在代码头部声明编码的方式有三种:
#coding=
#-*-coding:-*-
#vim:setfileencoding=
Vim中有关编码的选项:
在Vim中,有四个与编码有关的选项,它们是:fileencodings、fileencoding、encoding和termencoding。
Linux系统的编码设置:
Linux的系统编码设置可以通过设置locale来完成,直接在命令行敲locale,然后回车,即可查看当前系统的编码设置,与保存文件相关的设置是LC_CTYPE。
如LC_CTYPE=zh_CN.gb18030,即把系统的编码设置成为了gb18030。
以上内容为大家介绍了python终端输出乱码怎么解决?希望对大家有所帮助,如果想要了解更多Python相关知识,请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python中的filter函数功能是什么?
python中的filter函数功能是什么?在python中,面对众多的数据,我们要过滤筛选出我们需要的数据。python中的filter函数就是起到了过滤筛选的作...详情>>
2023-11-10 20:37:27
pythontime模块是什么
pythontime模块是什么在python中使用时间,就免不了和time模块打交道,另外两个模块这个暂时先不做介绍。做time模块的使用上,我们可以用它来对...详情>>
2023-11-10 15:53:16
python是什么编程语言
python是什么编程语言1、说明是一种面向对象、解释型计算机程序设计语言,由GuidovanRossum于1989年底发明,第一个公开发行版发行于1991年。Pyt...详情>>
2023-11-10 15:21:05
python异常处理的两种技巧
python异常处理的两种技巧1、传递异常有时我们会在捕捉到一个异常后重新引发它(传递异常),实现起来很简单,使用不带参数的raise语句即可。deff...详情>>
2023-11-10 14:49:39热门推荐
python中的filter函数功能是什么?
沸python delattr函数如何使用?
热python中pdb模块怎么用?
热Python如何截图保存?
新python中缺少module怎么办?
python strftime和strptime的不同分析
python time.strptime的格式化
python中@contextmanager是什么?
python对象的三要素是什么
pythonGIL在Python多线程的应用
python如何对多个CSV文件进行读取
pythonif嵌套命令如何理解?
python对列表进行永久性或临时排序的方法
python生成器调用方法引发异常
技术干货






