List for loops: 'list' object is not callable

Screen Link: https://app.dataquest.io/m/312/lists-and-for-loops/7/opening-a-file

My Code:

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
print(opened_file)
apps_data = list(read_file)

What I expected to happen:
Read in .csv file as list of lists

What actually happened:

TypeErrorTraceback (most recent call last)
<ipython-input-1-2bd46d983b10> in <module>()
      3 read_file = reader(opened_file)
      4 print(opened_file)
----> 5 apps_data = list(read_file)

TypeError: 'list' object is not callable

trying to go back and figure out where I messed up the ‘list()’ function, but this is the first reference and this is given code, which doesn’t compile

1 Like

Hello @asun1235, welcome to the community.

You probably assigned some object to a variable named list somewhere in your code. Therefore, even if you delete the code, the variable stays stored in the memory. When you then try to run list(read_file) it raises an error saying list is not callable.

Try to leave the mission before trying again.


Also, I edited your post to format the code properly.

2 Likes

Hello @asun1235 cause is same as @otavios.s describe if you still having problem.

Then Open Console in mission from bottom
image
type

>>> del list

and press Enter.

And then re-run your code it should work.

3 Likes

Hi had this same issue. had the correct code. tried leaving and returning to mission. also tried del list in Console - no luck.

just moving onto the next step for now.

1 Like

Hello @scottmackin, Can you give us more detail full error or your code?

2 Likes

Hi! Also experiencing the same issue when running the list () function. >>> del list doesn’t work either…

Here is the code :

from csv import reader

opened_file = open(‘AppleStore.csv’)

read_file=reader(opened_file)
apps_data=list(read_file)
apps_data = list(read_file)
len(apps_data)
print(apps_data[0])
print(apps_data[1:3])

And here are the comments ont the Output :

IndexErrorTraceback (most recent call last)
in ()
7 apps_data = list(read_file)
8 len(apps_data)
----> 9 print(apps_data[0])
10 print(apps_data[1:3])

IndexError: list index out of range

and then on the console, following “dell list” :slight_smile:
NameErrorTraceback (most recent call last)
in ()
----> 1 del list

NameError: name ‘list’ is not defined

1 Like

Hello @six.anneconstance,

Here you have different error it’s not related to this question.

The issue in your code is you have assisgned apps_data twice. list(read_file) second time return empty list.

Hence do

from csv import reader

opened_file = open(‘AppleStore.csv’)

read_file=reader(opened_file)
apps_data=list(read_file)

len(apps_data)
print(apps_data[0])
print(apps_data[1:3])

Great ! did not see that indeed!
Thank you :slight_smile:

1 Like

Hii! I am experiencing the same error while running the below code…

from csv import reader
opened_file = open(‘Applestore.csv’)
read_file= reader(opened_file)
apps_data= list(read_file)

print(len(apps_data))
print(apps_data[0])
print(apps_data[1:4])

The error for the above code is…

FileNotFoundError Traceback (most recent call last)
in
1 from csv import reader
----> 2 opened_file = open(‘Applestore.csv’)
3 read_file= reader(opened_file)
4 apps_data= list(read_file)
5

FileNotFoundError: [Errno 2] No such file or directory: ‘Applestore.csv’

Also, tried using the console del list but it gave the below output…
----> 1 del list

NameError: name ‘list’ is not defined

It would be great if someone can help. Thanks in advance

@Welcome to our community nitesh7258 NiteshJha!
Just change your file name from "Applestore.csv" to "AppleStore.csv".
Hope it will work for you :heart:

It worked… Python was punishing me for grammatical mistake.
Thank you for your help

1 Like

No worries!! :smiley:

Thank you for this, I was beginning to get discouraged :ok_woman:t5: :raising_hand_woman:t5:

1 Like