I really don't see the benefit of the one liner. You get the same information doing this:
print(args)
I do not understand what the problem is with the --os. This works fine for me:
import sys
import argparse
def get_args(args=sys.argv[1:]):
print("Parsing", args)
parser = argparse.ArgumentParser()
parser.add_argument("--os")
parser.add_argument("--eventtime")
return parser.parse_args(args)
print(get_args(["--os", "Windows Server 2016 Standard", "--eventtime", "2022-03-16 17:33:53 +0100"]))
print(get_args())
When I call it with these arguments:
Quote:python testargparse.py --os "Windows XP" --eventtime "Right Now"
I get this output.
Output:
Parsing ['--os', 'Windows Server 2016 Standard', '--eventtime', '2022-03-16 17:33:53 +0100']
Namespace(os='Windows Server 2016 Standard', eventtime='2022-03-16 17:33:53 +0100')
Parsing ['--os', 'Windows XP', '--eventtime', 'Right Now']
Namespace(os='Windows XP', eventtime='Right Now')
You are still being vague. "If i introduce --os it starts failing". Please include information about how it is failing. Also, it has been a long time since you posted any code. The last I saw was:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--host", help="Node Name") #taken
parser.add_argument("--IPAddress", help="Node Name") #taken
parser.add_argument("--service", help="Service Name")
parser.add_argument("--displayname", help="Display Name")
parser.add_argument("--environment", help="Environement") #Taken
parser.add_argument("--newstate", help="Current Type of the alert")
parser.add_argument("--appname", help="Application Name")
parser.add_argument("--hostappname", help="Host App Name") #taken
parser.add_argument("--priority", help="Priority") #taken
parser.add_argument("--output", help="Description") #taken
parser.add_argument("--eventtime", help="Event Time") #taken
parser.add_argument("--os", help="Operating System") #taken
parser.add_argument("--operator", help="Operator") #taken
parser.add_argument("--notificationtype", help="Notification Type Problem or Clear") #taken
parser.add_argument("--notification_default", help="Define which Operator") #taken
parser.add_argument("--operatoros", help="OS Group") #taken
parser.add_argument("--operatormw", help="Middleware Group") #taken
parser.add_argument("--division", help="Division")
parser.add_argument("--Info", help="Additional Information")
_error = parser.error
def error(message):
print('argparse parser error %s', message)
_error(message)
parser.error = error
arguments = parser.parse_args()
I know for sure that this is not the code you are currently running. If you really want help you need to post some updated code.