【发布时间】:2014-03-05 22:50:54
【问题描述】:
这段代码在while中总是给出一个无限循环:
pos1 = 0
pos2 = 0
url_string = '''<h1>Daily News </h1><p>This is the daily news.</p><p>end</p>'''
i = int(len(url_string))
#print i # debug
while i > 0:
pos1 = int(url_string.find('>'))
#print pos1 # debug
pos2 = int(url_string.find('<', pos1))
#print pos2 # debug
url_string = url_string[pos2:]
#print url_string # debug
print int(len(url_string)) # debug
i = int(len(url_string))
我尝试了一切都没有结果。
更多信息:
- Python 2.7.5+(默认,2013 年 9 月 19 日,13:48:49)
- [GCC 4.8.1] 在 linux2 上
- Ubuntu 13.10
- 在 GNOME 终端 3.6.1 中运行(也在 Emacs 和 PyCharm 中尝试过,但没有解决无穷大问题)
【问题讨论】:
-
你的调试输出是什么?这一定是一个很大的暗示。
print url_string -
注意:不需要
int转换并且html代码不是“url”。
标签: python-2.7 while-loop infinite-loop