|
|
|
|
 搞不明白为什么python会这样?? - blygl [ 2006-09-25 02:35 | 857 byte(s)]
 Re: 搞不明白为什么python会这样?? - zaxis [ 2006-09-26 09:35 | 115 byte(s)]
|
|
|
|
[Original]
[Print]
[Top]
|
怎么程序在python处带的python shell里写就以正常运行。而把同样的程序在editplus里或用记事本写就会出错呢?程序如下:
# coding: cp936
import MySQLdb
conn=MySQLdb.connect(host='localhost',user='root',passwd='123456',db='aa')
cursor=conn.cursor()
sql = u"""update users set login='测试' where id=2"""
cursor.execute(sql)
在editplus里出错信息如下:
---------- Python ----------
Traceback (most recent call last):
File "boa1.py", line 6, in ?
cursor.execute(sql)
File "D:PythonLibsite-packagesMySQLdbcursors.py", line 146, in execute
query = query.encode(charset)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 24-26: ordinal not in range(256)
|
|
|
[Original]
[Print]
[Top]
|
|
[Original]
[Print]
[Top]
|
try add the following line at the 1st line
# This Python file uses the following encoding: utf-8
|
|
|
----
LDMFD SP!, {R0-R12, PC}^
|
|
[Original]
[Print]
[Top]
|
|
|