Rahmadyan Nurwidhi
Rahmadyan Nurwidhi

Reputation: 3

AttributeError: 'tuple' object has no attribute 'translate'

AttributeError: 'tuple' object has no attribute 'translate'

mycursor = mydb.cursor()
mycursor.execute("SELECT content FROM news_tb")
myresult = mycursor.fetchall()
for row in myresult:
    row = row.translate(str.maketrans('', '', string.punctuation)).lower()


    tokens = word_tokenize(row)
    listStopword = set(stopwords.words('indonesian'))
    wordsFiltered = []

    for t in tokens:
        if t not in listStopword:
            wordsFiltered.append(t)
    print(wordsFiltered)

Traceback (most recent call last): File "C:/Users/Rahmadyan/PycharmProjects/Skripsi/nltk_download.py", line 17, in row = row.translate(str.maketrans('', '', string.punctuation)).lower() AttributeError: 'tuple' object has no attribute 'translate'

Upvotes: 0

Views: 1709

Answers (1)

jonyfries
jonyfries

Reputation: 854

Even though it is only returning a single column it still puts the value into a tuple just like it would if multiple values were returned.

Each row in the value is going to be something like ("hello",)

To get the string you'll need to access it like this row[0]

Upvotes: 1

Related Questions