解决Dask Bag模块AttributeError:无from_filenames属性问题
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 samechunkbytesparameter 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

