mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
Add class Options
The Options constructor takes an options string, parses it and makes the options available via __getitem__(). Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
a52557570b
commit
1ffdb8728a
3 changed files with 162 additions and 0 deletions
5
test/parse-opts/Makefile
Normal file
5
test/parse-opts/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TOPDIR = ../..
|
||||
|
||||
include $(TOPDIR)/make/proj.mk
|
||||
include $(JWBDIR)/make/py-run.mk
|
||||
|
||||
32
test/parse-opts/test.py
Normal file
32
test/parse-opts/test.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from jwutils.log import *
|
||||
from jwutils.Options import *
|
||||
|
||||
delim = "======================= "
|
||||
d = "----------------------- "
|
||||
|
||||
s = "this=that a=b doit"
|
||||
slog(NOTICE, d + s)
|
||||
a = Options(s)
|
||||
slog(NOTICE, d + "dump()")
|
||||
a.dump(NOTICE)
|
||||
slog(NOTICE, d + "by index")
|
||||
for i in range(0, 4):
|
||||
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index=True, default=False)))
|
||||
slog(NOTICE, d + "by key")
|
||||
for i in [ "this", "that", "b", "a", "doit"]:
|
||||
slog(NOTICE, "attr({}) = {}".format(i, a[i]))
|
||||
|
||||
s = '"me": "too", "Pfalse": true, "myarr": ["a", "b", "c"], "me": "not"'
|
||||
slog(NOTICE, delim + s)
|
||||
a = Options(s)
|
||||
slog(NOTICE, d + "dump()")
|
||||
a.dump(NOTICE)
|
||||
slog(NOTICE, d + "by index")
|
||||
for i in range(0, 5):
|
||||
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index=True, default=False)))
|
||||
slog(NOTICE, d + "by key in keys()")
|
||||
for i in a.keys():
|
||||
slog(NOTICE, "attr({}) = {}".format(i, a[i]))
|
||||
slog(NOTICE, d + "by key")
|
||||
for i in [ "me", "Pfalse", "myarr" ]:
|
||||
slog(NOTICE, "attr({}) = {}".format(i, a[i]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue