Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
3be4dd95
Commit
3be4dd95
authored
5 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
added some code to play with grid class object and the argument parsing
parent
e29b6ecb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
snippets/arg_test.py
+63
-0
63 additions, 0 deletions
snippets/arg_test.py
with
63 additions
and
0 deletions
snippets/arg_test.py
0 → 100644
+
63
−
0
View file @
3be4dd95
import
argparse
class
grid
(
object
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
grid_options
=
{}
def
load_grid_options
(
self
):
self
.
grid_options
=
{
'
test1
'
:
0
,
'
test2
'
:
1
,
}
def
argparse
(
self
):
"""
This function handles the arg parsing of the grid.
Make sure that every grid_option key/value is included in this,
preferably with an explanation on what that parameter will do
"""
parser
=
argparse
.
ArgumentParser
(
description
=
'
Arguments for the binary_c python wrapper grid
'
)
# add arguments here
parser
.
add_argument
(
'
--test1
'
,
type
=
int
,
help
=
'
input for test1
'
)
parser
.
add_argument
(
'
--test2
'
,
type
=
int
,
help
=
'
input for test2
'
)
# Load the args from the cmdline
args
=
parser
.
parse_args
()
# Copy current grid_option set
new_grid_options
=
self
.
grid_options
.
copy
()
# loop over grid_options
for
arg
in
vars
(
args
):
# print ("arg: {arg} value: {value}".format(arg=arg, value=getattr(args, arg)))
# If an input has been given in the cmdline: override the previous value of grid_options
if
getattr
(
args
,
arg
):
new_grid_options
[
arg
]
=
getattr
(
args
,
arg
)
# Put the new grid options back
self
.
grid_options
=
new_grid_options
.
copy
()
newgrid
=
grid
(
'
test
'
)
newgrid
.
load_grid_options
()
print
(
newgrid
.
grid_options
)
newgrid
.
argparse
()
print
(
newgrid
.
grid_options
)
# Custom set a single value:
newgrid
.
grid_options
[
'
test2
'
]
=
2
print
(
newgrid
.
grid_options
)
# Custom set multiple values:
newgrid
.
grid_options
.
update
({
'
test1
'
:
4
,
'
test2
'
:
-
2
,
})
print
(
newgrid
.
grid_options
)
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