Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oceano2python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
US191
Oceano2python
Commits
c7c77445
Commit
c7c77445
authored
6 years ago
by
jacques Grelet
Browse files
Options
Downloads
Patches
Plain Diff
remove key from dict
parent
9acb42df
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
physicalParameter.py
+9
-6
9 additions, 6 deletions
physicalParameter.py
tests/test_roscop.py
+5
-4
5 additions, 4 deletions
tests/test_roscop.py
with
14 additions
and
10 deletions
physicalParameter.py
+
9
−
6
View file @
c7c77445
...
@@ -50,11 +50,11 @@ class Roscop:
...
@@ -50,11 +50,11 @@ class Roscop:
theKey
=
row
[
reader
.
fieldnames
[
0
]]
theKey
=
row
[
reader
.
fieldnames
[
0
]]
for
k
in
reader
.
fieldnames
:
for
k
in
reader
.
fieldnames
:
# if the value of key is empty
# if the value of key is empty
if
row
[
k
]
==
''
:
if
row
[
k
]
==
''
or
k
==
'
key
'
:
# remove the key
# remove the key
row
.
pop
(
k
)
row
.
pop
(
k
)
else
:
else
:
#logging.debug(" %s -> %s: %s" % (theKey, k, row[k]))
#
logging.debug(" %s -> %s: %s" % (theKey, k, row[k]))
logging
.
debug
(
logging
.
debug
(
"
{} -> {}: {}
"
.
format
(
theKey
,
k
,
row
[
k
]))
"
{} -> {}: {}
"
.
format
(
theKey
,
k
,
row
[
k
]))
self
.
__hash
[
theKey
]
=
row
self
.
__hash
[
theKey
]
=
row
...
@@ -66,9 +66,8 @@ class Roscop:
...
@@ -66,9 +66,8 @@ class Roscop:
# ---------------------------------
# ---------------------------------
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
# display extra logging info
# usage:
# see: https://stackoverflow.com/questions/14097061/easier-way-to-enable-verbose-logging
# > python physicalParameter.py code_roscop.csv -k TEMP
# https://docs.python.org/2/howto/argparse.html
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
description
=
'
This class Roscop parse a csv file describing physical parameter codification
'
)
description
=
'
This class Roscop parse a csv file describing physical parameter codification
'
)
parser
.
add_argument
(
"
-d
"
,
"
--debug
"
,
help
=
"
display debug informations
"
,
parser
.
add_argument
(
"
-d
"
,
"
--debug
"
,
help
=
"
display debug informations
"
,
...
@@ -76,6 +75,10 @@ if __name__ == "__main__":
...
@@ -76,6 +75,10 @@ if __name__ == "__main__":
parser
.
add_argument
(
"
-k
"
,
"
--key
"
,
nargs
=
'
+
'
,
parser
.
add_argument
(
"
-k
"
,
"
--key
"
,
nargs
=
'
+
'
,
help
=
"
display dictionary for key(s), example -k TEMP [PSAL ...]
"
)
help
=
"
display dictionary for key(s), example -k TEMP [PSAL ...]
"
)
parser
.
add_argument
(
"
file
"
,
type
=
str
,
help
=
"
the csv file to parse
"
)
parser
.
add_argument
(
"
file
"
,
type
=
str
,
help
=
"
the csv file to parse
"
)
# display extra logging info
# see: https://stackoverflow.com/questions/14097061/easier-way-to-enable-verbose-logging
# https://docs.python.org/2/howto/argparse.html
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
args
.
debug
:
if
args
.
debug
:
logging
.
basicConfig
(
logging
.
basicConfig
(
...
@@ -95,5 +98,5 @@ if __name__ == "__main__":
...
@@ -95,5 +98,5 @@ if __name__ == "__main__":
for
k
in
key
:
for
k
in
key
:
r
.
displayCode
(
k
)
r
.
displayCode
(
k
)
print
(
r
.
returnCode
(
key
[
0
])[
'
key
'
])
print
(
"
{}: {}
"
.
format
(
key
[
0
],
r
.
returnCode
(
key
[
0
])[
'
long_name
'
])
)
# print(r[key])
# print(r[key])
This diff is collapsed.
Click to expand it.
tests/test_roscop.py
+
5
−
4
View file @
c7c77445
...
@@ -16,17 +16,18 @@ class RoscopTest(unittest.TestCase):
...
@@ -16,17 +16,18 @@ class RoscopTest(unittest.TestCase):
self
.
r
=
Roscop
(
self
.
file
)
self
.
r
=
Roscop
(
self
.
file
)
def
test_file
(
self
):
def
test_file
(
self
):
"""
"""
Test if filename is correct
"""
Test if filename is correct
"""
self
.
assertEqual
(
self
.
r
.
file
,
self
.
file
)
self
.
assertEqual
(
self
.
r
.
file
,
self
.
file
)
def
test_entries
(
self
):
def
test_entries
(
self
):
'''
test the number of entries in csv file
'''
self
.
assertEqual
(
len
(
self
.
r
),
68
)
self
.
assertEqual
(
len
(
self
.
r
),
68
)
def
test_key
(
self
):
def
test_key
(
self
):
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
TEMP
'
)[
'
key
'
],
'
TEMP
'
)
'''
test the standard_name for physical parameter TEMP
'''
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
TEMP
'
)[
'
standard_name
'
],
'
sea_water_temperature
'
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
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