Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Learn how to fix error: attributeerror: 'int' object has no attribute 'append'
Next
Answered
Tracy Anderson
  • 9
Tracy Anderson
Asked: May 18, 20222022-05-18T20:49:30+00:00 2022-05-18T20:49:30+00:00In: python

Learn how to fix error: attributeerror: ‘int’ object has no attribute ‘append’

  • 9

. Advertisement .

..3..

. Advertisement .

..4..

I get the “attributeerror: ‘int’ object has no attribute ‘append’” error as the title says. How can I fix it so the error goes away? Here is my detail:

import pyodbc,nltk,array,re,itertools
 cnxn = pyodbc.connect('Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Port=3306;Database=information_schema;User=root; Password=1234;Option=3;')
 cursor = cnxn.cursor()
 cursor.execute("use collegedatabase ;")
 cursor.execute("select * from sampledata ; ")
 cnxn.commit()
 s=[]
 j=[]
 x=[]
 words = []
 w = []
 sfq = []
 POS=[]
 wnl = nltk.WordNetLemmatizer()
 p = []
 clean= []
 l =[]
 tupletolist= []
 results = []
 aux = []
 regex = re.compile("\w+\.")
 pp = []
 array1=[]
 
 f = open("C:\\Users\\vchauhan\\Desktop\\tupletolist.txt","w")
 for entry in cursor:
  s.append(entry.injury_type),j.append(entry.injury_desc) 
 
 def isAcceptableChar(character):
  return character not in "~!@#$%^&*()_+`1234567890-={}|:<>?[]\;',/."
 
 
 from nltk.tokenize import word_tokenize
 from nltk.corpus import stopwords
 english_stops = set(stopwords.words('english'))
 for i in range(0,200):
  j.append(filter(isAcceptableChar, j[i]))
  w.append([word for word in word_tokenize(j[i].lower()) if word not in english_stops])
  for j in range (0,len(w[i])):
  results = regex.search(w[i][j])
  if results:
  str.rstrip(w[i][j],'.')
 for a in range(0 , 200):
  sfq.append(" ".join(w[a]))
 
 from nltk.stem import LancasterStemmer
 stemmer = LancasterStemmer()
 
 for i in range (0,200):
  pp.append(len(w[i]))
 
 for a in range (0,200):
  p.append(word_tokenize(sfq[a]))
  POS.append([wnl.lemmatize(t) for t in p[a]])
  x.append(nltk.pos_tag(POS[a]))
  clean.append((re.sub('()[\]{}'':/\-[(",)]','',str(x[a]))))
  cursor.execute("update sampledata SET POS = ? where SRNO = ?", (re.sub('()[\]{}'':/\-[(",)]','',str(x[a]))), a)
 
 for i in range (0,len(array1)):
  results.append(regex.search(array1[i][0]))
  if results[i] is not None:
  aux.append(i)
 
 f.write(str(w))

When I operated it, I received the error text:

Traceback (most recent call last):
  File "C:\Users\vchauhan\Desktop\regexsolution_try.py", line 37, in <module>
  j.append(filter(isAcceptableChar, j[i]))
 AttributeError: 'int' object has no attribute 'append'

I appreciate any help from you.

int object has no attribute append
  • 2 2 Answers
  • 115 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-29T10:40:33+00:00Added an answer on June 29, 2022 at 10:40 am

    The cause: When calling the append() method on an integer, the error “AttributeError: ‘int’ object has no attribute ‘append'” appears.

    Solution: J has been used as both an integer and a list. Only use j as an integer name; give the list a different name.

    j.append(filter(isAcceptableChar, j[i])) # j is not a list here,it is an int.
    w.append([word for word in word_tokenize(j[i].lower()) if word not in english_stops])
    for j in range (0,len(w[i])): # here j is an int
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Chloë Maurin
    2022-05-25T21:10:06+00:00Added an answer on May 25, 2022 at 9:10 pm

    The following section of your code is worth a closer look:

    for i in range(0,200):
     j.append(filter(isAcceptableChar, j[i]))
     w.append([word for word in word_tokenize(j[i].lower()) if word not in english_stops])
     for j in range (0,len(w[i])):

    You can see how .append is called on j, which you had initialized earlier with a list. Then you use it as a loop variable that is nested within the same loop.

    To avoid these errors, use meaningful and better variable names in your code. You can rename the loop variable or module-level list variable.

    • 12
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.