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
a9a58377
Commit
a9a58377
authored
6 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
test with dict
parent
160bf4aa
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
+23
-8
23 additions, 8 deletions
roscop/roscop.py
with
23 additions
and
8 deletions
roscop/roscop.py
+
23
−
8
View file @
a9a58377
...
...
@@ -20,22 +20,35 @@ class Roscop:
# constructor with values by default
def
__init__
(
self
,
file
):
self
.
file
=
file
self
.
hash
=
{}
# call by print()
def
__
rep
r__
(
self
):
#print("%s:" % row[key], end='')
def
__
st
r__
(
self
):
#
print("%s:" % row[key], end='')
# print()
return
"
class Roscop, file: {}
"
.
format
(
self
.
file
)
return
'
Class Roscop, file: %s, size = %d
'
%
(
self
.
file
,
len
(
self
.
hash
))
def
disp
(
self
,
theKey
):
db
=
self
.
hash
[
theKey
]
# print(dict(db))
# print(db.items())
# read code roscop file
def
read
(
self
):
print
(
"
Code roscop file: %s
"
%
self
.
file
)
d
=
db
(
)
with
open
(
self
.
file
,
'
rt
'
)
as
f
:
reader
=
csv
.
DictReader
(
f
,
delimiter
=
'
;
'
)
#print("%s" % (reader.fieldnames))
for
key
in
reader
.
fieldnames
:
d
.
key
=
key
for
row
in
reader
:
d
=
db
()
for
key
in
reader
.
fieldnames
:
d
.
key
=
row
[
key
]
theKey
=
row
[
reader
.
fieldnames
[
0
]]
for
k
in
reader
.
fieldnames
:
d
.
k
=
row
[
k
]
self
.
hash
[
theKey
]
=
d
#print("Key : %s" % theKey)
return
...
...
@@ -43,5 +56,7 @@ class Roscop:
# ---------------------------------
if
__name__
==
"
__main__
"
:
from
roscop
import
Roscop
r
=
Roscop
(
"
code_roscop.csv
"
).
read
()
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