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
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 3,100 Jan-21-2024, 01:12 PM
Last Post: owalahtole
  problem in using input command akbarza 4 1,151 Oct-19-2023, 03:27 PM
Last Post: popejose
  Reading an Input File DaveG 1 1,260 Mar-27-2022, 02:08 AM
Last Post: deanhystad
  Problem with input after function luilong 10 4,117 Dec-04-2021, 12:16 AM
Last Post: luilong
  Hashing an address for binary file Python_help 8 2,649 Nov-04-2021, 06:23 AM
Last Post: ndc85430
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,637 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  single input infinite output problem Chase91 2 1,957 Sep-23-2020, 10:01 PM
Last Post: Chase91
  How to assign input file name as logger name Mekala 5 2,880 Aug-05-2020, 12:54 AM
Last Post: Larz60+
  syntaxerror when entering a constructor MaartenRo 2 1,996 Aug-03-2020, 02:09 PM
Last Post: MaartenRo
  Problem with the input marios 4 2,077 May-03-2020, 01:01 PM
Last Post: marios

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020