androidpythonjythonmonkeyrunner

monkeyrunner as REPL?


Question

Given that by running monkeyrunner without arguments it starts a REPL session where I can use monkey runner python classes and modules.

Is there a way to also load a python class in there and test that class using the REPL?

What I tried

I've tried reading the manual but other than saying that there are command line flags/options it doesn't list them anywhere that I can see.

Running man monkeyrunner doesn't yield any reference manual. Nor does monkeyrunner -help or monkeyrunner -h or monkeyrunner --help.

I've tried cding myself into the folder with the abc.py file, but import abc on the monkeyrunner REPL doesn't load the module by giving a ImportError: No module named abc.


Solution

  • Be sure the path to your module is in sys.path. IIRC monkeyrunner does not honor PYTHONPATH.

    Alternatively, you can use AndroidViewClient/culebra as a replacement and you will be able to do from python. Assuming there's a mod.py on your current directory:

    $ python -i
    Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import com.dtmilano.android.viewclient
    >>> import mod
    I'm mod
    >>>