Because i don't want to use this syntax because it is too long, I want a
direct access :
Not :
DicoUser['TOTO'].DicoTable.['MY_TABLE'].DicoLabel.['MY_LABEL'] = "for
exemple"
Finally, i want to use :
TOTO.MY_TABLE.MY_LABEL = "for exemple"
What's with the dotted notation? Looks like a dialect of REXX's
stem variables. Though even those do not do variable translation for the
first item -- you couldn't do
aUser = "TOTO"
aUser.MY_TABLE.MY_LABEL = ...
Yes, I know Python has dotted notation, but for accessing
members of modules or class instances, and I'd be leery of any code that
was using string variables to access into those.
What sort of data structure are you trying to access?
-=-=-=-=-=-=-=-
# need to initialize some test data first
tLabel = {"MY_LABEL" : "Some junk",
"OTHER LABEL" : "Other junk"}
tTable = {"MY_TABLE" : tLabel,
"OTHER_TABLE" : {"THIRD LABEL" : "More junk"} }
Users = {"TOTO" : tTable}
print
# Okay, put the strings into variables
aUser = "TOTO"
aTable = "MY_TABLE"
aLabel = "MY_LABEL"
# access something in the data
print Users[aUser][aTable][aLabel]
# change something in the data
Users[aUser][aTable][aLabel] = "For Example"
# show the whole structure
print Users
#access the changed item, using literals and variables mixed
print Users["TOTO"][aTable]["MY_LABEL"]
-=-=-=-=-=-=-=-=-
Some junk
{'TOTO': {'OTHER_TABLE': {'THIRD LABEL': 'More junk'}, 'MY_TABLE':
{'MY_LABEL': 'For Example', 'OTHER LABEL': 'Other junk'}}}
For Example
The REXX equivalent would look something like (I've not done
REXX in a decade):
Users."TOTO"."MY_TABLE"."MY_LABEL" = "Some junk"
Users."TOTO"."MY_TABLE"."OTHER LABEL" = "Other junk"
Users."TOTO". "OTHER_TABLE"."THIRD LABEL" = "More junk"
aUser = "TOTO"
aTable = "MY_TABLE"
aLabel = "MY_LABEL"
say Users.aUser.aTable.aLabel
Users.aUser.aTable.aLabel = "For example"
/* no equivalent for printing the entire structure */
say Users."TOTO".aTable."MY_LABEL"
--