LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Why without strings gives en error?

Screen Link: Learn data science with Python and R projects

My Code without string:

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:3])

What I expected to happen:
why without any string on opened_file = open(AppleStore.csv) it gives an error? while if I provide string then opened_file = open('AppleStore.csv') or opened_file = open("AppleStore.csv") then it works!

What actually happened:

Traceback (most recent call last):
  File "/tmp/52e9a2fbcd68ea13f0586eda9c9c672c5fc82231.py", line 86, in run_code_string
    exec(code, variables)
  File "<string>", line 3, in <module>
NameError: name 'AppleStore' is not defined

Hi Jannat,

As far as my understanding of the error goes, if you are passing the AppleStore without the quotations (or string as you call it), the computer (or coding environment) is recognizing that you are passing a variable.

Hence, you get the error “NameError: name ‘AppleStore’ is not defined”.

You’ll be able to understand how methods work as you go along the course like how I did.

I hope my response gave you a bit of clarity. :slight_smile:

Hi there, thanks for suggestions!