---
title: "python的字符编码问题"
author: "sd6292766"
date: "2013-07-29T17:03:09Z"
tags: []
categories: ["编程语言"]
slug: "python"
draft: false
lastmod: "2013-07-29T17:03:09Z"
id: 1915004
url: "https://babystudyjava.iteye.com/blog/1915004"
---

最近因为项目需要用到PYTHON脚本，赶紧学习了一下。今天碰到一个问题，做下笔记。就是出现类似“Non-UTF-8 code starting with '\xb6' in file xxxxx.py”这样的报错，错误原因网上都有解释：是PYTHON的文件编码问题，因此根据官方提示，需要加入#coding = 你要指定的编码。

    其次，在调试过程中发现，转换文件编码的语句：
```python
#coding = utf-8
```
<span style="color:red">**这句必须放在文件第一行或者第二行的位置**</span>

    以此做个记号，谨记。