Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4029758
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:23:09+00:00 2026-05-20T11:23:09+00:00

I some lines of code that read a csv file in a certain format.

  • 0

I some lines of code that read a csv file in a certain format. What I’d like now (and couldn’t figure out a solution for) is that the file name stops being stale and becomes an actual user input when calling the python program. Now I have a static file name in the code, eg:

reader = csv.reader(open("file.csv", "rb"))

I’d like this to become an information provided by the user. Is this done using raw_input or is there a way to do it by having the user writing something in the lines of:

python testfile.py --input:file.csv

Appreciate your help in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:23:09+00:00Added an answer on May 20, 2026 at 11:23 am

    For reference the optparse (http://docs.python.org/library/optparse.html) version would look something like this.

    import optparse
    
    parser = optparse.OptionParser()
    parser.add_option("-i","--input",dest="filename")
    (options,args) = parser.parse_args()
    
    thefile = options.filename
    reader = csv.reader(thefile,"rb")
    

    Which would let you call either

    python script.py -i foo.dat
    python script.py --input foo.dat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar questions: Some characters in CSV file are not read during PHP fgetcsv() ,
I am reading some lines from a file in the following format: Identifier String
I am trying to read some code that I did not write. In the
I'm writing some code that uses dynamic shared libraries as plugins. My command line
Please suggest some free tools which will help me to get Lines-of-Code metrics for
I'm trying to insert some import lines into a python source file, but i
I have developed application for drawing some shapes (lines mostly) , now i need
I have a incomplete csv file that needs to be accurately updated, so there
I have a file in CSV format where the delimiter is the ASCII unit
Summary: I have a struct that is read/written to file. This struct changes frequently,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.