Oct-18-2023, 08:16 AM
hi
i read https://realpython.com/introduction-to-p...enerators/
there is a file as techcruch.csv in the above address.
I downloaded it on my desktop, so its address on my PC is: C:\Users\akbar\Desktop\techcruch.csv
in the below code(IDLE):
the below error is displayed:
thanks
i read https://realpython.com/introduction-to-p...enerators/
there is a file as techcruch.csv in the above address.
I downloaded it on my desktop, so its address on my PC is: C:\Users\akbar\Desktop\techcruch.csv
in the below code(IDLE):
1 2 3 4 5 6 7 8 9 10 11 12 13 |
address = r "C:\Users\akbar\Desktop\techcruch.csv" def csv_reader(file_name): for row in open (file_name, "r" ): yield row def y(address): csv_gen = csv_reader(address) row_count = 0 for row in csv_gen: row_count + = 1 print ( f "Row count is {row_count}" ) y(address) |
Error:Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
y(address)
File "<pyshell#26>", line 5, in y
for row in csv_gen:
File "<pyshell#2>", line 2, in csv_reader
for row in open(file_name, "r"):
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\akbar\\Desktop\\techcruch.csv'
I also did the below tests and you can see what idle showed to me:1 |
address = "C:\Users\akbar\Desktop\techcruch.csv" |
Error:SyntaxError: incomplete input
1 2 |
address = r "C:\Users\akbar\Desktop\techcruch.csv" address |
Output:'C:\\Users\\akbar\\Desktop\\techcruch.csv'
1 |
address = f "C:\Users\akbar\Desktop\techcruch.csv" |
Error:SyntaxError: incomplete input
1 2 |
address = r "C:\Users\akbar\Desktop\techcruch.csv" y(address) |
Error:Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
y(address)
File "<pyshell#26>", line 5, in y
for row in csv_gen:
File "<pyshell#2>", line 2, in csv_reader
for row in open(file_name, "r"):
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\akbar\\Desktop\\techcruch.csv'
so what can I do to input the address of the techcruch.csv file to the y function?thanks