Q:

Can't pass values via command line

I have to write a program that reads from a file and writes some analysis to a text file. The program has to take some information via the command line but I can't see, to figure it out even given the template. I wrote a test program to see if I could succesfully pass command line input to the class.
#!/usr/bin/env python3

########################################################################
# CommandLine
########################################################################
class CommandLine() :
    '''
    Handle the command line, usage and help requests.

    CommandLine uses argparse, now standard in 2.7 and beyond. 
    it implements a standard command line argument parser with various argument options,
    a standard usage and help, and an error termination mechanism do-usage_and_die.

    attributes:
    all arguments received from the commandline using .add_argument will be
    avalable within the .args attribute of object instantiated from CommandLine.
    For example, if myCommandLine is an object of the class, and requiredbool was
    set as an option using add_argument, then myCommandLine.args.requiredbool will
    name that option.

    '''

    def __init__(self, inOpts=None) :
        '''
        CommandLine constructor.
        Implements a parser to interpret the command line argv string using argparse.
        '''

        import argparse
        self.parser = argparse.ArgumentParser(description = 'Program prolog - a brief description of what this thing does', 
                                             epilog = 'Program epilog - some other stuff you feel compelled to say', 
                                             add_help = True, #default is True 
                                             prefix_chars = '-', 
                                             usage = '%(prog)s [options] -option1[default] <input >output'
                                             )
        self.parser.add_argument('inFile', action = 'store', help='input file name')
        self.parser.add_argument('outFile', action = 'store', help='output file name') 
        self.parser.add_argument('-lG', '--longestGene', action = 'store', nargs='?', const=True, default=True, help='longest Gene in an ORF')
        self.parser.add_argument('-mG', '--minGene', type=int, choices= range(0, 2000), action = 'store', help='minimum Gene length')
        self.parser.add_argument('-s', '--start', action = 'append', nargs='?', help='start Codon') #allows multiple list options
        self.parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1')  
        if inOpts is None :
            self.args = self.parser.parse_args()
        else :
            self.args = self.parser.parse_args(inOpts)

########################################################################
#MAIN GOES HERE
########################################################################

def main(myCommandLine=None):
    '''
    Implements the Usage exception handler that can be raised from anywhere in process.  

    '''

    myCommandLine = CommandLine(myCommandLine)

        #myCommandLine.args.inFile #has the input file name
        #myCommandLine.args.outFile #has the output file name
        #myCommandLine.args.longestGene #is True if only the longest Gene is desired
        #myCommandLine.args.start #is a list of start codons
        #myCommandLine.args.minGene #is the minimum Gene length to include

    print (myCommandLine.args) # print the parsed argument string .. as there is nothing better to do

    if myCommandLine.args.longestGene:
        print ('longestGene is', str(myCommandLine.args.longestGene) )
    else :
        pass
    class Test:
        def __init__(self):
            print(myCommandLine.args.minGene)

if __name__ == "__main__":
    main()

class Test:
    def __init__(self):
        self.test()

    def test(self, infile = myCommandLine.args.inFile, outfile = myCommandLine.args.outFile, longest = myCommandLine.args.longestGene, start = myCommandLine.args.start, min = myCommandLine.args.minGene):
        print(infile)
        print(outfile)
        print(longest)
        print(start)
        print(min)

new_obj = Test()

The command line input should look like: python testcommand.py -minG 100 -longestG -starts ATG tass2ORFdata-ATG-100.txt
Supposedly the main program goes where it says "MAIN GOES HERE" but when I tried that I got an error that "myCommandline is not defined". So I moved the program to the end. But I get the error 'the '>' operator is reserved for future use"
I'm using Powershell if that matters. How do I get this data into my class?

A:

You don't need CommandLine class. As suggested by James Mills, here is an example: 
import argparse

class Test:
    def __init__(self, infile, outfile, longest, start, min):
        self.infile = infile
        self.test()

    def test(self):
        print(self.infile)

def main():
    parser = argparse.ArgumentParser(description = 'Program prolog', 
                                     epilog = 'Program epilog', 
                                     add_help = True, #default is True 
                                     prefix_chars = '-', 
                                     usage = 'xxx')
    parser.add_argument('-i', '--inFile', action = 'store', help='input file name')
    parser.add_argument('-o', '--outFile', action = 'store', help='output file name') 
    parser.add_argument('-lG', '--longestGene', action = 'store', nargs='?', const=True, default=True, help='longest Gene in an ORF')
    parser.add_argument('-mG', '--minGene', type=int, choices= range(0, 20), action = 'store', help='minimum Gene length')
    parser.add_argument('-s', '--start', action = 'append', nargs='?', help='start Codon') #allows multiple list options
    parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1')  
    args = parser.parse_args()
    test = Test(args.inFile, args.outFile, args.longestGene, args.minGene, args.start)

if __name__ == '__main__':
    main()

