SyntaxError:非ASCII字符'\ xd1'

时间:2012-11-03 15:41:39

标签: python sql ms-access encoding character-encoding

我写了以下代码

conAcc = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\ThirdTask\Northwind.accdb')
SqlAccess=conAcc.cursor();
SqlAccess.execute(sql.sql_count_record_clients);
CountOfRecords=SqlAccess.fetchone();
conAcc.close();

模块sql.py中有一行

sql_count_records_clients='''SELECT COUNT(*) FROM "Список клиентов"'''

结果是sql.py中的这一行发出错误

Traceback (most recent call last):
  File "D:\ThirdTask\connect.py", line 5, in <module>
    import json,sqlite3,sql
  File "D:\ThirdTask\sql.py", line 48
SyntaxError: Non-ASCII character '\xd1' in file D:\ThirdTask\sql.py on line 48, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

如何使错误消失?

1 个答案:

答案 0 :(得分:2)

需要添加第一行代码:

# -*- coding: utf-8 -*- 
enter code here

然后解决问题