Oct-19-2023, 12:17 PM
(Oct-19-2023, 06:05 AM)akbarza Wrote: 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):
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)the below error is displayed:
I also did the below tests and you can see what idle showed to me:
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'
address="C:\Users\akbar\Desktop\techcruch.csv"
Error:SyntaxError: incomplete inputaddress=r"C:\Users\akbar\Desktop\techcruch.csv" address
Output:'C:\\Users\\akbar\\Desktop\\techcruch.csv'address=f"C:\Users\akbar\Desktop\techcruch.csv"
Error:SyntaxError: incomplete inputaddress=r"C:\Users\akbar\Desktop\techcruch.csv" y(address)so what can I do to input the address of the techcruch.csv file to the y function?
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'
thanks
no reply yet?