0
$\begingroup$

Here 20_newsgroups is a folder which contain 20 folder and each folder contain some file , i just want to make datasets containind words and file name

its gives Error append() takes exactly one argument (2 given)

X = [] # an element of X is represented as (filename,text)
Y = [] # an element of Y represents the newsgroup category of the corresponding X element
for category in os.listdir('20_newsgroups'):
    for document in os.listdir('20_newsgroups/'+category):
        with open('20_newsgroups/'+category+'/'+document, "a+") as f:
            X.append(document,f.read())
            Y.append(category)
$\endgroup$
0
$\begingroup$

The problem is that you are passing two arguments to append:

X.append(document,f.read())

You probably want a tuple, in which case you should modify the line to

X.append((document, f.read()))

or

X += [(document, f.read())]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.