- 论坛徽章:
- 0
|
本帖最后由 ZX424 于 2010-05-26 16:11 编辑
问题已经解决了,是回车符导致的问题,非常感谢各位的关注.
ip文件(无空行或空格):
192.168.1.1
192.168.1.2
192.168.1.3
password文件(无空行或空格):
password1
password2
password3
运行:
- #!/usr/bin/python
- IP = open('ip.txt','r')
- PASSWORD = open('pass.txt','r')
- while 1:
- READIP=IP.readline()
- READPASS=PASSWORFD.readline()
- print READIP
- print READPASS
- if not READIP
- break
- print 'ALL DONE'
复制代码 得到结果为:
192.168.1.1
password1
192.168.1.2
password2
192.168.1.3
password3
ALL DONE
发现输出结果每行当中都会多出一个回车符号,于是我就想会不会是回车符导致的,接着百度了一下,在原来的代码上加了2行:
- #!/usr/bin/python
- IP = open('ip.txt','r')
- PASSWORD = open('pass.txt','r')
- while 1:
- READIP=IP.readline()
- READPASS=PASSWORFD.readline()
- READIP = READIP.rstrip() # 清除回车符
- READPASS = READPASS.rstrip() # 清除回车符
- print READIP
- print READPASS
- if not READIP
- break
- print 'ALL DONE'
复制代码 运行的结果为:
192.168.1.1
password1
192.168.1.2
password2
192.168.1.3
password3
ALL DONE
之后再放回原来的代码中就能正常跳出循环了. |
|