SyntaxError: Non-ASCII character '\xe5' in file D:/pcode/xx.py on line 21, but no encoding declared

from selenium import webdriver
from datetime import *
import time starttime = datetime.now()
print ("start time:%s" %starttime)
dr = webdriver.Firefox() url = "http://www.sohu.com"
print('now access %s' %url) dr.get(url)
#time.sleep(3) endtime = datetime.now()
print ("end time:%s"%endtime) print("u共花费毫秒:",endtime-starttime).microseconds dr.quit()

  报错:SyntaxError: Non-ASCII character '\xe5' in file D:/pcode/xx.py on line 21, but no encoding declared

修改后成功代码:

#coding=utf-8
from selenium import webdriver
from datetime import *
import time starttime = datetime.now()
print ("start time:%s" %starttime)
dr = webdriver.Firefox() url = "http://www.sohu.com"
print('now access %s' %url) dr.get(url)
#time.sleep(3) endtime = datetime.now()
print ("end time:%s"%endtime) info = u'共花费时间:(秒)'
print(info.encode('utf-8')+str((endtime-starttime).seconds)) dr.quit()

  

上一篇:设子数组A[0:k]和A[k+1:N-1]已排好序(0≤K≤N-1)。试设计一个合并这2个子数组为排好序的数组A[0:N-1]的算法。


下一篇:一些Android程序的反逆向方法