Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 脚本只运行到for循环中的某个点,然后停止,没有错误:使用_Python_Loops_Search_Text_Exit - Fatal编程技术网

Python 脚本只运行到for循环中的某个点,然后停止,没有错误:使用

Python 脚本只运行到for循环中的某个点,然后停止,没有错误:使用,python,loops,search,text,exit,Python,Loops,Search,Text,Exit,我有一个名为urlclean的数据框架,其形式如下: >>> urlclean Matches Searching for URL List URL Status 14 2 Green Index http://greenindex.timberland.com/ Works 由于它是从一个初步数据帧派生出来的,所以第1行的索引是“14”。我已经编写了第二个代码,在“URL列表”中打开URL,并在

我有一个名为urlclean的数据框架,其形式如下:

>>> urlclean
Matches Searching for                           URL List URL Status
14       2   Green Index  http://greenindex.timberland.com/      Works
由于它是从一个初步数据帧派生出来的,所以第1行的索引是“14”。我已经编写了第二个代码,在“URL列表”中打开URL,并在所选URL的文本中搜索“搜索”(本例中为绿色索引)下所有可能重复的短语,如下所示:

for cindex, row in urlclean.iterrows():
    print("starting clea nup")
    sentence=[]
    sentence=urlopen(urlclean.loc[cindex,'URL List']).read()
    print("opening urls")

    soup=[]
    soup=BeautifulSoup(sentence)
    print("Getsoup")
    rsentence=[]
    rsentence=(soup.get_text())

    print("gettect")
    indices = (i for i,word in enumerate(rsentence) if word==
    (urlclean.loc[cindex,'Searching for']))
    print("getting indices")
    neighbors = []

    for ind in indices:
        neighbors.append(rsentence[ind-2:ind]+rsentence[ind:ind+2])
        print("opening rsetence",(rsentence[ind-
        2:ind]+rsentence[ind:ind+2]))
        Resulting=[]
        print("got Neighbors", neighbors)
        N=len(neighbors)

        for indexx in range(0,N):
            Resulting_TEMP=[]
            Resulting_TEMP=[(' '.join(map(str,neighbors[indexx])))]
            print("resulting temp",Resulting_TEMP)
            urlclean.loc[cindex,'All Phrases']=Resulting_TEMP
            Resulting.append(Resulting_TEMP)
            print("got results", Resulting)    
我包括print()以跟踪我的代码运行的时间点,它从字面上输出我以前派生的数据帧,然后在编写后存在上述代码:

starting cleanup
opening urls
Getsoup
gettect
getting indices
>>> 

它从不启动在ind和index之间的for循环,我是否遗漏了什么?我是python新手,如果这是一个基本问题,我深表歉意。

一个空格的缩进量确实不足以使代码可读。Python中预期的缩进量是4个空格。@khelwood哦,对不起,你是指在这个网站上阅读缩进,还是在执行我的代码时?两者都是。Python解释器当然会抱怨缩进不一致,但在您发布的代码中,许多行缩进一个空格,不清楚这些行是应该缩进四个空格,还是根本不缩进。如果你检查并纠正你的缩进,这会很有帮助。编辑它,现在有意义了吗?在for的每次迭代之前,我添加了4个空格,因为它们是嵌套循环@davidz。您能验证
索引
是否已填充吗?您可以尝试调试器,也可以简单地进行
打印(len(index))
检查。一个空格的缩进确实不足以使代码可读。Python中预期的缩进量是4个空格。@khelwood哦,对不起,你是指在这个网站上阅读缩进,还是在执行我的代码时?两者都是。Python解释器当然会抱怨缩进不一致,但在您发布的代码中,许多行缩进一个空格,不清楚这些行是应该缩进四个空格,还是根本不缩进。如果你检查并纠正你的缩进,这会很有帮助。编辑它,现在有意义了吗?在for的每次迭代之前,我添加了4个空格,因为它们是嵌套循环@davidz。您能验证
索引
是否已填充吗?您可以尝试调试器,或者只需执行
打印(len(index))
即可进行检查。