Skip to content

Instantly share code, notes, and snippets.

@IotaSpencer
Last active November 21, 2016 00:41
Show Gist options
  • Save IotaSpencer/fb8c18e3e967937f01ff8f69c3d58684 to your computer and use it in GitHub Desktop.
Save IotaSpencer/fb8c18e3e967937f01ff8f69c3d58684 to your computer and use it in GitHub Desktop.
ken@home:~$ python3 test1.py 1 password digest
1
['password', 'digest']
['password', 'digest']
Not enough arguments. Needs 1-2, password, digest
Traceback (most recent call last):
File "test1.py", line 32, in <module>
raise NotEnoughArgumentsError(requires, arguments)
<unknown>NotEnoughArgumentsError: (1, ['password', 'digest'])
#! /usr/bin/env python3
import sys
args = sys.argv[1:]
requires = int(args[0])
arguments = args[1:]
print(requires)
print(arguments)
class NotEnoughArgumentsError(Exception):
__module__ = None
"""Exception raised when there are not enough arguments
Attributes:
requires - an integer that is the number of REQUIRED arguments
arguments - comma seperated list of arguments that such a command needs
"""
def __init__(self, required_amount, args):
print(args)
self.required_amount = required_amount
self.arguments = args
ourstring = ""
if len(arguments) > required_amount:
ourstring = "%s-%s" % (required_amount, len(args))
ourargs = self.arguments
ourargstring = ", ".join(ourargs)
print("Not enough arguments. Needs %s, %s" % (ourstring, ourargstring))
return None
raise NotEnoughArgumentsError(requires, arguments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment