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

no reply yet?
Reply


Messages In This Thread
problem in using input command - by akbarza - Oct-19-2023, 06:05 AM
RE: problem in using input command - by akbarza - Oct-19-2023, 12:17 PM
RE: problem in using input command - by deanhystad - Oct-19-2023, 01:45 PM
RE: problem in using input command - by snippsat - Oct-19-2023, 01:50 PM
RE: problem in using input command - by popejose - Oct-19-2023, 03:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with print command in super() akbarza 5 697 Feb-01-2024, 12:25 PM
Last Post: deanhystad
  problem in entering address of a file in input akbarza 0 702 Oct-18-2023, 08:16 AM
Last Post: akbarza
  Facing Problem while opening a file through command prompt vlearner 4 2,002 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Problem with input after function luilong 10 4,243 Dec-04-2021, 12:16 AM
Last Post: luilong
  How to input & output parameters from command line argument shantanu97 1 2,625 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,704 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  single input infinite output problem Chase91 2 1,998 Sep-23-2020, 10:01 PM
Last Post: Chase91
  Problem with the input marios 4 2,119 May-03-2020, 01:01 PM
Last Post: marios
  Taking Multiple Command Line Argument Input bwdu 6 4,136 Mar-29-2020, 05:52 PM
Last Post: buran
  command line input (arg parse) and data exchange Simba 7 4,403 Dec-06-2019, 11:58 PM
Last Post: Simba

Forum Jump:

User Panel Messages

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