#系统环境:
Centos 7 X64
Python 3
##示例 1:
import pexpect
with open('ftp.log', "w") as f:
child =pexpect.spawn('yum remove ftp', encoding='utf-8',logfile=f,searchwindowsize=20)
child.expect('\[y\/N\]')
child.sendline('y')
##示例 2:
import pexpect
def test():
with open('test.log', "w") as f:
child =pexpect.spawn('yum remove ftp', encoding='utf-8',logfile=f,searchwindowsize=20)
child.expect('\[y\/N\]')
child.sendline('y')
test()
以上两段代码,使用示例 1 可以卸载 ftp,但在示例 2 中却无法卸载 ftp, 而 ftp.log 和 test.log 的输出是相同的,对,完全相同! 代码不同之处仅仅是示例 2 中的代码封装成了函数而已, 实在不明白为什么示例 2 无法按照预期进行操作, 莫非这个问题是库的坑?#手动滑稽
4 条回复 • 2018-01-01 22:59:18 +08:00
|
1
cyclelost 2018 年 1 月 1 日 via iPhone child.before 看看呗
|
|
2
Xiaobaixiao OP @cyclelost 正文说了输出日志完全相同啊……
|
|
3
lolizeppelin 2018 年 1 月 1 日 via Android wai 了没有
|
|
4
Xiaobaixiao OP |
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide