How do I add sys.argv to a function opening a text file in Python
<p>I need to use sys.argv to check for an argument from the command line, which would be the filename in my case. My code is as follows. I'm not allowed to import argparse, only allowed to use sys. I know I'm doing something wrong here. Appreciate any help. </p>

<pre><code>def get_inputfile_object( ):
    '''
    Check the command line for an argument.  If one was there, use it as the
    filename.  Otherwise, use DEFAULT_INPUT_FILENAME.  Open the file.

    If file is successfully opened:
        print MSG_OPENING_FILE
        Return: a file object for that file

    If the file cannot be opened:
        print MSG_ERROR_OPENNING_FILE
        Return: True
    '''
    if sys.argv &gt; 1:
        pass
    else:
        input_filename = DEFAULT_INPUT_FILENAME

    input_filename = DEFAULT_INPUT_FILENAME
    if os.path.isfile(input_filename) and os.access(input_filename,os.R_OK):
        #Prints the opening file message, and the name of the file
        print (MSG_OPENING_FILE,input_filename)
        return open(input_filename,'r')
    else:
        print (MSG_ERROR_OPENING_FILE)
        return True
</code></pre>