Airbourne Airbourne - 11 days ago 7
Python Question

Changing function arguments in python

I want to remove the command line arguments from the following code and give arguments through code

# Handle arguments
parser = argparse.ArgumentParser()
parser.add_argument('--target', required=True)
parser.add_argument('--policy', required=True)
parser.add_argument('--name', required=True)
parser.add_argument('--insecure', action="store_true")
parser.add_argument('--ca_bundle')
args = parser.parse_args()

# Log in
scan = rest.Scanner(url=_url, login=login, password=password, insecure=args.insecure, ca_bundle=args.ca_bundle)

# Set policy that should be used
scan.policy_set(name=args.policy)


I want to convert the code so that I can pass arguments from code instead of command line. Some thing like this

a=target
b=policyname
c=scan_name
d=xyz
args=(a,b,c,d)
scan = rest.Scanner(url=_url, login=login, password=password, insecure=args.d, ca_bundle=args.ca_bundle)

scan.policy_set=(name=args.b)


How can this be done?

Answer

Simply pass the parameters directly.

scan = rest.Scanner(url=a,password=b,insecure=true,.....)
Comments