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 7849835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:39:28+00:00 2026-06-02T18:39:28+00:00

My program takes 2 or 3 command line parameters: -s is an optional parameter,

  • 0

My program takes 2 or 3 command line parameters:

-s is an optional parameter, indicating a switch in my program later on
-infile is the file input
-outfile is to be the written file

I need my program to print an error message and quit if any of the following happen:

  • the user specifies an infile name that does not end with .genes
  • the user specifics an outfile name that does not end with either .fa or .fasta
  • the user provides less than 2, or more than 3, parameters
  • the user’s first parameter starts with a dash, but is not ‘-s’

I have written:

def getGenes(spliced, infile, outfile):
spliced = False
if '-s' in sys.argv:
    spliced = True
    sys.argv.remove('-s')
    infile, outfile = sys.argv[1:]
if not infile.endswith('.genes'):
    print('Incorrect input file type')
    sys.exit(1)
if not outfile.endswith('.fa' or '.fasta'):
    print('Incorrect output file type')
    sys.exit(1)
if not 2 <= len(sys.argv) <= 3:
    print('Command line parameters missing')
    sys.exit(1)
if sys.argv[1] != '-s':
    print('Invalid parameter, if spliced, must be -s')
    sys.exit(1)

However, something is conflicting with some of the conditionals, including the first and last one being contradictory due to the fact that s.argv[1] always unequal to ‘-s’ becuase if ‘s’ were present in argv, it was removed earlier. So I am not sure how to write this correctly…

  • 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-02T18:39:30+00:00Added an answer on June 2, 2026 at 6:39 pm

    sliced=False is not indented

    def getGenes(spliced, infile, outfile):
         spliced = False
    

    sys.argv.remove('s') it should be sys.argv.remove('-s')

    two conditions are contradicting each other:

    if '-s' in sys.argv:
        spliced = True
        sys.argv.remove('-s') # you removed '-s' from sys.argv ,so the below if condition becomes false
        infile, outfile = sys.argv[1:]  
    
    if sys.argv[1] != '-s':
        print('Invalid parameter, if spliced, must be -s')
        sys.exit(1)
    

    Edited version of your code:

    import sys
    
    def getGenes(spliced, infile, outfile):
     spliced = False
    if '-s' in sys.argv:
        spliced = True
        infile, outfile = sys.argv[2:]
    if not infile.endswith('.genes'):
        print('Incorrect input file type')
        sys.exit(1)
    if not outfile.endswith('.fa' or '.fasta'):
        print('Incorrect output file type')
        sys.exit(1)
    if not 3 <= len(sys.argv) <= 4:
        print('Command line parameters missing')
        sys.exit(1)
    if sys.argv[1] != '-s':
        print('Invalid parameter, if spliced, must be -s')
        sys.exit(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My C/C++ program takes a file from the command line as an argument. Reading
Summary I have written a process monitor command-line application that takes as parameters: The
I have a completely non-interactive python program that takes some command-line options and input
I need to make a program, ioloop.c, which takes two command line parameters that
I'm writing a program in C++ and it takes some command line arguments. The
I'm writing a program, which takes two words as command line arguments, does something
I have to write a program that takes a command-line argument n and prints
I have an application that takes various command line parameters. This works fine but
I have an existing java command-line program, that takes a bazillion of arguments and
I'm writing a program that takes a single command line argument. This argument needs

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.