You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解决Dask Bag模块AttributeError:无from_filenames属性问题

Fixing AttributeError: module 'dask.bag' has no attribute 'from_filenames'

Hey there, I see you're trying to load Reddit comments into a Dask Bag and hitting that attribute error—let's get this sorted out quickly!

The issue here is that the from_filenames method for Dask Bag has been deprecated and removed in newer versions of Dask. It's been replaced by the more intuitive read_text method, which handles exactly the same functionality you're after (reading text files in chunks and creating a Bag).

Corrected Code

Replace your original code with this updated version:

import dask.bag as db
import json  # Don't forget to import json if you haven't already!

# Use read_text instead of from_filenames
data = db.read_text("reddit_1_28_2018.txt", chunkbytes=100000).map(json.loads)

Why This Works

  • db.read_text() is now the standard way to load text files into a Dask Bag. It supports the same chunkbytes parameter you were using to control how large each chunk of data is.
  • After reading the text chunks, you still use .map(json.loads) to parse each line (assuming your Reddit data is stored as one JSON object per line, which is typical for Pushshift exports).

Quick Check

If you're working with an older version of Dask and still want to confirm, you can check your Dask version with:

import dask
print(dask.__version__)

I recommend upgrading to the latest stable version of Dask to take advantage of all the latest features and fixes.

内容的提问来源于stack exchange,提问作者Parseltongue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:16:45