PEXPECT in python



  • Hi All,

    I am looking at a great command in python called pexpect. As I understand it, you can spawn any python program and then extract the output you want from it from a different python program.

    This is what I wish to do:
    I have a program that will return a GPS co-coordinate in a long string but I wish to only get the co-ordinates from it and not the whole string. I am not sure if this is the easiest way of doing this but I wanted the main program to be looking out for other things as well at the same time so I came up with spawning a python script separate to the main program.

    Lets say that the output of the spawn is xxxx.yyyyy.zzzz <cr><lf>

    I need the info yyyyy back in the main program so that I can process it.

    My problem is that I have python 2.7.9 and looking at the documents for pexpect, it only allows the commands I need to run on version 3 python - See http://pexpect.readthedocs.io/en/stable/install.html#requirements

    I can install python3 (and have done) using, "opkg install python3" but when I install pexpect, it puts it under 2.7.9

    root@Omega-1F15:/# python3 --version
    Python 3.4.3
    root@Omega-1F15:/# pip install -U pip
    Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages

    As a result, my python3 pexpect still doesn't work in python3.

    Does anybody know what I am doing wrong?
    Am I able to spawn a python 2.7 program whilst running python 3 as a main program.
    Is there a better way to get a scripting type of chat going between two programs like this - such as - send xxx and wait for yyy?

    Thanks... :-)



  • I don't have my Omega to hand, but I found this that might help

    http://stackoverflow.com/questions/10763440/how-to-install-python3-version-of-package-via-pip-on-ubuntu

    But thinking about the limited storage you might want to remove python 2.x if you are not going to use it and that will stop pip installing to python 2.x

    Mark



  • Thanks - that looks like the best answer.. I have, however, since tried to cross compile python3 and had to start again.. :-/ So now I have a different problem that wasn't there before and I'm not doing anything different - I can't get python3 running as well as the normal version2.

    I will post a different thread for that one. Then come back to your solution.. Thanks..


Log in to reply
 

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.