问题描述:
monkeyrunner执行python脚本报错:
C:\Users\Administrator>monkeyrunner E:\monkeyrunner\kyb_start.py
201210 14:24:36.820:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
201210 14:24:36.820:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]SyntaxError: Non-ASCII character in file 'E:\monkeyrunner\kyb_start.py', but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
原因分析:
脚本中含有中文字符,需在脚本开头注明编码格式
解决方法:
在脚本代码开头添加以下代码:
# -*- coding: UTF-8 -*-
重新执行脚本,即可运行成功
# -*- coding: UTF-8 -*-
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice as md