目前列出的.replace()解决方案没有解决我的问题

时间:2014-03-18 00:05:10

标签: python

我刚刚尝试过类似我之前的问题所建议的语法,但它对我没用。我试过了:

newvar = str(oldvar)
newvar = newvar.replace('\r', '').replace('\n', ' ')

我尝试过:

newvar = oldvar.replace('\r', '').replace('\n', ' ')

我的完整(相关)代码部分在这里:

URLS = myurls2.values()

# Retrieve a single page and report the url and contents
def load_url(key, url, timeout):
    conn = urllib.request.urlopen(url, timeout=timeout)
    return conn.readall()


# We can use a with statement to ensure threads are cleaned up promptly
with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
    # Start the load operations and mark each future with its URL
    future_to_url = {executor.submit(load_url, key, url, 60): (key, url)
                 for key, url in myurls2.items()}
    c = 0


    for future in concurrent.futures.as_completed(future_to_url):
        key, url = future_to_url[future]    

        try:
            data = str(future.result())
            data2 = str(data)
            data2 = data2.replace('\r', '').replace('\n', ' ')
            print(data2)
            d = open(filepath,"w")
            d.write(data2)
            d.close()

字典值转换为提交给相关网站的网址,然后最后我希望将它们转换为字符串并删除替换语句中列出的字符。

由于

0 个答案:

没有答案