简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM