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

  • SEARCH
  • Home
  • 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 8468877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:04:01+00:00 2026-06-10T16:04:01+00:00

I currently have a python file that utilizes sys.argv[1] to accept a string at

  • 0

I currently have a python file that utilizes sys.argv[1] to accept a string at the command line. It then performs operations on that string and then returns the modified string to the command line.

I would like to implement a batch mode option in which I can provide a file of strings (one per line, fwiw) and have it return to the command line so that I can redirect the output doing something like

$ python script.py -someflag file.txt > modified.txt 

while still retaining the current capabilities.

I am only running 2.6, so argparse is not an option. The tutorials I have seen either use argparse, getopt, or delve into examples that are too complex/don’t apply.

What is the best way to check the input and act appropriately?

  • 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-06-10T16:04:03+00:00Added an answer on June 10, 2026 at 4:04 pm

    argparse is still an option, it’s just not built into 2.6. You can still install it like any 3rd party package (for example, using easy_install argparse).

    An example of code for this would be:

    import sys
    import argparse
    
    p = argparse.ArgumentParser(description="script.py")
    p.add_argument("-s", dest="string")
    p.add_argument("-f", dest="infile")
    
    args = p.parse_args()
    
    if args.infile == None and args.string == None:
        print "Must be given either a string or a file"
        sys.exit(1)
    if args.infile != None and args.string != None:
        print "Must be given either a string or a file, not both"
        sys.exit(1)
    if args.infile:
        # process the input file one string at a time
    if args.string:
        # process the single string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some python code that currently performs expensive computation by performing the computation
I have a python file that will not correctly perform an import. If I
I currently have a python script that runs every few minutes and picks up
I currently have a number of Python scripts that help prep a staging area
I have a python program that I am currently working on which is working
I am currently working with Python and have been confused over the fact that
I have a Python script that takes the directory path of a text file
I have a Python script that reads a file (typically from optical media) marking
I have a python script that parses an XML file that contains part information
I currently have a list of genes in a file. Each line has a

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.