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
fa62f39f
Commit
fa62f39f
authored
6 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
use argpass and logging module
parent
2e7e64fe
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
roscop/roscop.py
+25
-13
25 additions, 13 deletions
roscop/roscop.py
with
25 additions
and
13 deletions
roscop/roscop.py
+
25
−
13
View file @
fa62f39f
"""
code roscop
"""
import
csv
import
shelve
import
sys
# class roscop
# ------------
import
logging
import
argparse
class
Roscop
:
# constructor with values by default
'''
This class read a csv file describing physical parameter with ROSCOP codification
'''
# constructor with values by default
def
__init__
(
self
,
file
):
self
.
file
=
file
self
.
hash
=
{}
...
...
@@ -34,11 +32,12 @@ class Roscop:
for
row
in
reader
:
theKey
=
row
[
reader
.
fieldnames
[
0
]]
for
k
in
reader
.
fieldnames
:
# if the value of key empty
, remove the key
# if the value of key
is
empty
if
row
[
k
]
==
''
:
# remove the key
row
.
pop
(
k
)
else
:
print
(
k
,
row
[
k
])
logging
.
debug
(
"
%s: %s
"
%
(
k
,
row
[
k
])
)
self
.
hash
[
theKey
]
=
row
return
...
...
@@ -47,8 +46,21 @@ class Roscop:
# for testing in standalone context
# ---------------------------------
if
__name__
==
"
__main__
"
:
# from roscop import Roscop
r
=
Roscop
(
"
code_roscop.csv
"
)
# display extra logging info
# see: https://stackoverflow.com/questions/14097061/easier-way-to-enable-verbose-logging
parser
=
argparse
.
ArgumentParser
(
description
=
'
This class Roscop parse a csv file describing physical parameter codification
'
)
parser
.
add_argument
(
"
-d
"
,
"
--debug
"
,
help
=
"
display debug informations
"
,
action
=
"
store_true
"
)
parser
.
add_argument
(
"
file
"
,
type
=
str
,
help
=
"
the csv file to parse
"
)
args
=
parser
.
parse_args
()
if
args
.
debug
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# Read the csv file and create an instance of Roscop class
r
=
Roscop
(
args
.
file
)
#r = Roscop("code_roscop.csv")
r
.
read
()
print
(
r
)
# r.disp('TEMP')
...
...
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