Python Forum
problem in entering address of a file in input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem in entering address of a file in input
#1
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:
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:

address="C:\Users\akbar\Desktop\techcruch.csv"
Error:
SyntaxError: incomplete input
address=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 input
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  email address input jacksfrustration 5 4,099 Jun-26-2024, 08:35 AM
Last Post: DeaD_EyE
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 4,735 Jan-21-2024, 01:12 PM
Last Post: owalahtole
  problem in using input command akbarza 4 4,523 Oct-19-2023, 03:27 PM
Last Post: popejose
  Reading an Input File DaveG 1 2,307 Mar-27-2022, 02:08 AM
Last Post: deanhystad
  Problem with input after function luilong 10 7,262 Dec-04-2021, 12:16 AM
Last Post: luilong
  Hashing an address for binary file Python_help 8 4,963 Nov-04-2021, 06:23 AM
Last Post: ndc85430
  Problem restricting user input in my rock paper scissors game ashergreen 6 7,851 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  single input infinite output problem Chase91 2 3,227 Sep-23-2020, 10:01 PM
Last Post: Chase91
  How to assign input file name as logger name Mekala 5 5,165 Aug-05-2020, 12:54 AM
Last Post: Larz60+
  syntaxerror when entering a constructor MaartenRo 2 3,233 Aug-03-2020, 02:09 PM
Last Post: MaartenRo

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.