![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
nestargs is a Python library that treats command line arguments as a hierarchical structure. The functionality for interpreting command line arguments is the same as argparse.
pip install nestargs
When defining command line arguments, use "." as the delimiter. to represent a variable hierarchy. The following code example defines an n
and price
variable in the apple
hierarchy and another separate n
and price
variable in the banana
hierarchy.
import nestargs
parser = nestargs.NestedArgumentParser()
parser.add_argument("--apple.n", type=int)
parser.add_argument("--apple.price", type=float)
parser.add_argument("--banana.n", type=int)
parser.add_argument("--banana.price", type=float)
args = parser.parse_args(
["--apple.n=2", "--apple.price=1.5", "--banana.n=3", "--banana.price=3.5"]
)
# => _NestedNamespace(apple=_NestedNamespace(n=2, price=1.5), banana=_NestedNamespace(n=3, price=3.5))
Variables obtained by parsing command line arguments can be referenced by hierarchy.
args.apple
# => _NestedNamespace(n=2, price=1.5)
Of course, you can also refer directly to variables lower down in the hierarchy.
args.apple.price
# => 1.5
When referring to each level of hierarchy, you can use vars
to create a dictionary format.
vars(args.apple)
# => {'n': 2, 'price': 1.5}
The default namespace delimiter is "." but can be any other character. In that case, specify the delimiter in the NestedArgumentParser
constructor argument.
import nestargs
parser = nestargs.NestedArgumentParser(delimiter="/")
parser.add_argument("--apple/n", type=int)
args = parser.parse_args(["--apple/n=1"])
# => _NestedNamespace(apple=_NestedNamespace(n=1))
However, references to variables must be separated by "." delimiter when referring to variables.
args.apple.n
# => 1
FAQs
Nested arguments parser
We found that nestargs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.