簡體   English   中英

在運行中,Jupyter筆記本大約90%的時間不打印任何內容

[英]On run, Jupyter notebooks prints nothing around 90% of the time

我的代碼-打開一個包含鏈接列表的csv文件,每個鏈接包含一個簡歷,在簡歷中打印文本,基本觀點和相應的鏈接-有時只能使用。

本來我以為該代碼不起作用,但實際上它起作用了,到目前為止,我已經成功地完成了幾次打印,但是很少見。

文件“ test.csv”僅包含三個鏈接,並且非常小。 筆記本似乎沒有思考。

我在Graph Lab Create中使用Jupyter筆記本,並且成功獲取了Microsoft安裝和OSX安裝上的打印結果。 現在我在Mac上,當我按Shift + Enter時沒有任何反應。 在轉到[num]之前,我得到了一個短暫的[*],但沒有任何結果。

我嘗試將其拆分為三個單獨的單元並立即執行。 僅在將代碼拆分為三個單元格之后,該方法才起作用。

有人遇到過這個問題嗎? 任何建議,將不勝感激。

Python 2.7

import urllib
from bs4 import BeautifulSoup
from textblob import TextBlob

all_links = open('test.csv', 'r')

for links in all_links:
    html = urllib.urlopen(links).read()
    soup = BeautifulSoup(html, "lxml")

    for script in soup(["script", "style"]):
        script.extract()

        text = soup.get_text()

        lines = (line.strip() for line in text.splitlines())
        chunks = (phrase.strip() for line in lines for phrase in line.split("  "))
        text = '\n'.join(chunk for chunk in chunks if chunk)

        words = text.encode('utf-8')
        sent = words.decode('utf-8')

        dec_sent = TextBlob(sent)

        print links, words, dec_sent.sentiment.polarity

您的問題可能是由於以下事實:您在for循環中定義了wordsdec_sent並根本沒有links ,但是可以從先前的單元格中重用...

如果html為空,則循環不會運行,因此您沒有定義這些var,並且應該得到一個錯誤(或正在打印以前運行的值)。

重新啟動jupyter內核並重新執行所有單元格,也許還可以print locals()來查看已定義的變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM