mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
The Options constructor takes an options string, parses it and makes the options available via __getitem__(). Signed-off-by: Jan Lindemann <jan@janware.com>
32 lines
999 B
Python
32 lines
999 B
Python
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]))
|