10

I would like to use an expect-like module in python3. As far as I know, neither pexpect nor fabric work with python3. Is there any similar package I can use? (If no, does anyone know if py3 support is on any project's roadmap?)

A perfectly overlapping feature set isn't necessary. I don't think my use case is necessary here, but I'm basically reimplementing a Linux expect script that does a telnet with some config-supplied commands, but extending functionality.

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
belacqua
  • 543
  • 4
  • 18
  • 4
    have you tried using 2to3 on pexpect to see if it works then? The expect fork http://pypi.python.org/pypi/pexpect-u/ says that it works that way, so maybe expect does too. – Niek de Klein May 15 '12 at 15:11
  • 1
    @NiekdeKlein, 2to3 is a very basic tool that does not account for many different issues; I would be astounded if a project the size of pexpect "just works" by merely running 2to3. Even if this did appear to "work", how could you expect to get support from the author if anything went wrong? BTW, for all essential purposes, pexpect has been abandoned by Noah... his last sourceforge code commit was in 2008 – Mike Pennington May 15 '12 at 19:09
  • @Mike Pennington I was just saying it worked for a fork of pexpect, so there is a chance that it also works for pexpect itself. It takes minimum time to test it (just run the program and see if it works). If it doesn't, no harm done. If it does, all the better. – Niek de Klein May 17 '12 at 09:22
  • 2
    @NiekdeKlein, I have been working with different flavors of expect libraries professionally for over 15 years; if someone wants to play around with an experiment like that go for it. However, some of us have been through enough hard knocks in life to avoid toying with this given all the complications under the hood of expect-like products. My paycheck depends on consistency and repeatability, regardless of inputs to the system. – Mike Pennington May 17 '12 at 12:14

2 Answers2

8

As Niek mentioned, I ported pexpect, and called it pexpect-u (u for unicode):

http://pypi.python.org/pypi/pexpect-u/

It uses 2to3, but I had to make some changes to the code as well before it worked.

I'm not very interested in maintaining it, but I couldn't get in touch with the author of pexpect, and I felt it was useful enough to be worth publishing. If you're interested in working on it, the code is on Bitbucket. My own need for it was very basic, so there may be bugs I haven't found.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
  • As @belacqua points out in another answer, Pexpect-u is now defunct, and Pexpect itself supports Python 3. – Thomas K Jun 02 '14 at 17:45
2

Happily, pexpect now supports python 3 (as of 2013 if not earlier).

It appears that @ThomasK has been able to add his pexpect-u Python 3 functionality (with some API changes) back into the main project. (Thanks Thomas!)

belacqua
  • 543
  • 4
  • 18