简体   繁体   English

pexpect中的问题(python3.3)

[英]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 在CentOS 7上运行3.3 python。尝试编写简单的脚本,但如果我使用解释器python 3.3,则无法使pexpect模块正常工作,我可以正确编写此命令

    [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 但是如果我使用完全相同的命令运行文件pexpect.py,我会得到

    [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. 我在Google中找到了一些类似的信息,建议是将.py文件移动到另一个文件夹。 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. 另一个建议是删除“ pycache ”文件夹(在我的pexpect.py位置中有相同的文件夹),但是它也不起作用。 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 . 您已将文件pexpect.py You need to rename it to something else as you are importing from your file not the pexpect module. 从文件而不是pexpect模块导入时,需要将其重命名为其他pexpect You also need to delete any .pyc in the same folder. 您还需要删除同一文件夹中的任何.pyc 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. 将脚本移到什么位置都没有关系,当前文件夹仍将位于实际pexpect模块所在的路径之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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