• Register
1 vote
565 views

Problem:

I am newbee in python program and I wrote this code:

def DeletChar(e, b) : 
      
    counts = e.count(b) 
     
  
       
    while counts : 
                 
        e.remove(b) 
  
        counts -= 1
   
 
      
    print(e) 
  
if __name__ == '__main__' : 
      
    e = "LOVENOTLOLOVE"
    DeletChar(e,'L') 

But this code gives me the following error:

Traceback (most recent call last):
  File "proc.py", line 20, in <module>
    DeletChar(e,'L') 
  File "main.py", line 9, in DeletChar
    e.remove(b) 
AttributeError: 'str' object has no attribute 'remove'

Can anyone help me out to fix this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote

Answer:

In your problem you are just counting the “e” but it do not belong to a list or it do not carry any value or any attribute thats why you are getting this error message. You should write your code like:

def DeletChar(e, b) : 
      
    counts = e.count(b) 
     
    e = list(e) 
       
    while counts : 
                 
        e.remove(b) 
  
        counts -= 1
   
 
      
    print(e) 
  
if __name__ == '__main__' : 
      
    e = "LOVENOTLOLOVE"
    DeletChar(e,'L') 

Hope you understand and this may solve your problem

11 6 4
34,950 points

Related questions

0 votes
1 answer 310 views
310 views
Python 3.3.2 import json & urllib.request Json [{"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}] print(response.info()) Date: Sun, 20 Oct 2013 07:06:51 GMT Server: Apache X-Powered-By: PHP/5.4.12 Content ... line 271, in load return loads(fp.read(), AttributeError: 'str' object has no attribute 'read' >>> . Any idea how i can fix this issue?
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 620 views
620 views
Problem: I am working on the sort function but while doing a small problem I am getting a error can you please what I am doing wrong,Program that takes a list of student name and sorts them to create a class roll number. The list of names will be given on line separated by ... item.sort(lambda x, y: cmp(x.lower(),y.lower())) print(item) AttributeError: 'str' object has no attribute 'sort'" Error"
asked Jun 9, 2020 Gavin 15.3k points
0 votes
1 answer 10 views
10 views
Problem: The code is the following (I am new to Python/Mysql): import mysql.connector conn = mysql.connector.connect(host='localhost',user='user1',password='puser1',db='mm') cursor = conn.cursor() string1 = 'test1' insert_query = """INSERT INTO items_basic_info (item_name) VALUES (%s)""", (string1) cursor.execute(insert_query) conn.commit() When I run this code I get this error:
asked 5 days ago Mashhoodch 9.1k points
0 votes
1 answer 23 views
23 views
Problem: I have a small problem with list. So i have a list called l: l = ['Facebook;Google+;MySpace', 'Apple;Android'] And as you can see I have only 2 strings in my list. I want to separate my list l by ';' and put my new 5 strings into a new list called ... tried to do this like this: l1 = l.strip().split(';') But Python give me an error: AttributeError: 'list' object has no attribute 'strip'
asked Feb 13 Mashhoodch 9.1k points
0 votes
1 answer 11 views
11 views
Problem: From Python: Attribute Error - 'NoneType' object has no attribute 'something': NoneType what means that instead of an instance of whatever Class or Object you think you're working with? you've actually got None. what That usually means that an assignment or function call up above failed or returned an unexpected result?
asked Jan 27 Mashhoodch 9.1k points
0 votes
1 answer 21 views
21 views
Problem: The CSV file contains 37 attributes + the label (last column). it doesn't contain header or index. Exp of the 1st row: 63651000000.0,63651000000.0,153.1,0,0,0,0,0,0,5,1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 ... "csv2libsvm.py", line 47, in <module> headers = reader.next() AttributeError: '_csv.reader' object has no attribute 'next' Do you have any idea about the problem ?
asked Jan 9 Mashhoodch 9.1k points
0 votes
1 answer 435 views
435 views
When trying to find the index of v but it gave me: 'numpy.ndarray' object has no attribute 'index' none of them have answered my question v = np.random.randn(10) print(v) maximum = np.max(v) minimum = np.min(v) print(maximum, minimum) v.index(maximum, minimum)
asked Oct 30, 2020 psandprop 2.4k points
0 votes
1 answer 107 views
107 views
Why does this code give AttributeError? internship = parser.find_all('a', attrs = {'title': lambda job: job.startswith('Internship')}) while this one works: internship = parser.find_all('a', attrs = {'title': lambda job: job and job.startswith('Internship') ... , in _matches return match_against(markup) File "<stdin>", line 1, in <lambda> AttributeError: 'NoneType' object has no attribute 'start
asked Oct 30, 2020 psandprop 2.4k points
0 votes
0 answers 159 views
159 views
function anagrams(s1, s2) is a Boolean valued function, which returns true just in case the string s1 contains the same letters as string s2 but in a different order. The function should be case insensitive --- in other words it should return the same value if any letters in either s1 or ... ; Ayxan Haqverdili Nov 12 '18 at 15:43 I've no idea..... maybe my logic is wrong, the output is so wired...
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 158 views
158 views
This line: sift = cv2.xfeatures2d.SIFT_create() return error: Traceback (most recent call last): File "C:/Python27/openCVskrypty/GUI/SOLUTION2.py", line 11, in <module> sift = cv2.xfeatures2d.SIFT_create() AttributeError: 'module' object has no attribute 'xfeatures2d' I ... ) and I haven't got xfeatures2d module. Does anyone know why? Can I download it separately? Thanks for help how fix this.
asked Oct 24, 2020 psandprop 2.4k points