• Register
1 vote
780 views

Problem:

Hello all,

I have started learning python recently. I installed python 3.2 on my Linux machine. I come to know about a function .clear() that clears the value inside a list. I am trying to clear the values of my list but it’s not working for my case, and returning an error  What could be the reason behind it? Please pull me up you have the legit answer. Thanks.
Find my sample code snippet below

>>> list = [10, 20, 30, 40, 50, 60, 70]
>>> list.clear()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'clear'

 

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

The reason behind it is very simple. The list.clear() function is compatible with only for python 3.3 and later version. It was introduced in python 3.3 version. To fix the error you may install the latest python version. If you are too lazy to do that you can use del list [ : ] instead.

Thanks

13 9 6
94,240 points

Related questions

1 vote
1 answer 3.1K views
3.1K views
Problem: I have a dictionary with some users' data in it. Trying to use the dictionary to call with .append() function but it throws an error that says attributeerror: 'list' object has no attribute 'keys' But I haven&rsquo;t declared it as a list in my program. Where am I doing wrong? Could ... = {} n = 0 for i in dict.keys(): new[i] = entry(n) n += 1 dict.append(new) Many thanks for your help.
asked Apr 5, 2020 Gavin 15.3k points
0 votes
1 answer 17 views
17 views
Problem: I want to count the number of times a word is being repeated in the review string I am reading the csv file and storing it in a python dataframe using the below line reviews = pd.read_csv("amazon_baby.csv") The code in the below lines work when I apply it to a single review. print reviews["review"][1] a = reviews["review"][1].split("disappointed") print a b = len(a) print b
asked 3 days ago Mashhoodch 9.1k points
0 votes
1 answer 12 views
12 views
Problem: attributeerror: 'series' object has no attribute 'reshape'
asked Feb 18 charles mathews 3.8k 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 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 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
0 votes
1 answer 104 views
104 views
Using Python Regex to retrieve certain content from a search box on a webpage with selenium.webDriver searchbox = driver.find_element_by_class_name("searchbox") searchbox_result = re.match(r"^.*(?=(\())", searchbox).group() The code works as long as the search box ... is error: AttributeError: 'NoneType' object has no attribute 'group' How can I make the script handle the "No results" situation?
asked Oct 24, 2020 psandprop 2.4k points