Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pygwinc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gwinc
pygwinc
Commits
6c66dbd7
Commit
6c66dbd7
authored
6 years ago
by
Jameson Graef Rollins
Browse files
Options
Downloads
Patches
Plain Diff
struct: add more useful dict methods
parent
3b228698
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!17
Quantum quadrature noise
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gwinc/struct.py
+32
-4
32 additions, 4 deletions
gwinc/struct.py
with
32 additions
and
4 deletions
gwinc/struct.py
+
32
−
4
View file @
6c66dbd7
...
...
@@ -75,6 +75,12 @@ class Struct(object):
##########
def
__init__
(
self
,
**
kwargs
):
"""
Arguments can pre-fill the structure
"""
self
.
__dict__
.
update
(
kwargs
)
def
__getitem__
(
self
,
key
):
"""
Get a (possibly nested) value from the struct.
...
...
@@ -85,11 +91,33 @@ class Struct(object):
else
:
return
self
.
__dict__
[
key
]
def
__setitem__
(
self
,
item
,
value
):
self
.
__dict__
[
item
]
=
value
def
get
(
self
,
key
,
default
):
"""
Get a (possibly nested) value from the struct, or default.
"""
try
:
return
self
[
key
]
except
KeyError
:
return
default
def
__setitem__
(
self
,
key
,
value
):
self
.
__dict__
[
key
]
=
value
def
setdefault
(
self
,
key
,
default
):
return
self
.
__dict__
.
setdefault
(
key
,
default
)
def
items
(
self
):
return
self
.
__dict__
.
items
()
def
keys
(
self
):
return
self
.
__dict__
.
keys
()
def
values
(
self
):
return
self
.
__dict__
.
values
()
def
__contains__
(
self
,
key
):
return
key
in
self
.
__dict__
def
__contains__
(
self
,
item
):
return
item
in
self
.
__dict__
def
to_dict
(
self
,
array
=
False
):
"""
Return nested dictionary representation of Struct.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment