How does Python (or MonkeyRunner) locate imported modules?

痴心易碎 提交于 2019-12-04 20:53:30

For your reference, the android SDK does appear to have a bug in it where the first item on sys.path is the monkeyRunner lib and the working directory mashed together. I added the following to fix.

import sys
sys.path.append(sys.path[0].split(':',1)[1])
import util

You need to add the module to the search path (you are cwd is not in the same dir?)

http://docs.python.org/2/tutorial/modules.html

import sys sys.path.append('/path/to/your/module')

The directory where the script is located is automatically added to sys.path by monkeyrunner (and this works pretty well for other OSs, unfortunately it seems you are using one where it doesn't). Then other modules present in the same directory of the script can be imported without problems.

That is, screenshots.py should find utils.py because the directory functional-tests is in sys.path.

You can verify its content by doing

import sys
print sys.path
import util

in screenshots.py. My guess is that all those c:\ are messing with the path.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!