Marat Fakhrutdinov
Marat Fakhrutdinov

Reputation: 45

Problems in pexpect (python3.3)

Running 3.3 python on CentOS 7. Tryin' to write simple script but can't get pexpect module to work as I want if I use interpreter python 3.3, I can write this commands correctly

    [root@localhost expect]# python3.3
    Python 3.3.3 (default, Apr  7 2015, 02:31:24)
    [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pexpect
    >>> child = pexpect.spawn('telnet 10.1.1.1')

but If I run file pexpect.py with exactly same commands, I get

    [root@localhost expect]# python3.3 /usr/etc/pexpect.py
    Traceback (most recent call last):
      File "/usr/etc/pexpect.py", line 1, in <module>
        import pexpect
      File "/usr/etc/pexpect.py", line 3, in <module>
        child = pexpect.spawn('telnet 10.1.1.1');
    AttributeError: 'module' object has no attribute 'spawn'

I found some similar info in the google, advice was to move .py file to another folder. It didn't work for me. Another advice was to delete " pycache" folder (I've got same in my pexpect.py location), but it didn't work aswell. Errors are still the same, this folder are still created after running the script (trying, I mean). Any ideas?

Upvotes: 2

Views: 3426

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180512

You have called your file pexpect.py. You need to rename it to something else as you are importing from your file not the pexpect module. You also need to delete any .pyc in the same folder. It does not matter where you move your script, the current folder is still going to be in the path before where the actual pexpect module is.

Upvotes: 3

Related Questions