0

Is there any variable in python similar to Matlab structures?

I would like to create a structure within another structure as in Matlab, but in Python. I've looking into Python Dictionaries, but I have not find an easy way to access to its values. Which in Matlab is really easy.

In Matlab I would do the following:

Create the structure

structure.parent1.variable1 = 23;
structure.parent1.variable2 = 19;
structure.parent1.variable3 = 19;
structure.parent2.variable1 = 10;
structure.parent2.variable2 = 11;

structure = 

    parent1: [1x1 struct]
    parent2: [1x1 struct]

And then access to the variable simply tipying

structure.parent2.variable1

ans =

    10
1
  • 3
    Have you considered using Python classes? Commented May 12, 2014 at 14:05

2 Answers 2

3

what is wrong with dictionaries in python - to create and then access them :

structure = {}
structure["parent1"] = {}
structure["parent1"]["variable1"] = 23;
structure["parent1"]["variable2"] = 19;
structure["parent1"]["variable3"] = 19;
structure["parent2"] = {}
structure["parent2"]["variable1"] = 10;
structure["parent2"]["variable2"] = 11;
Sign up to request clarification or add additional context in comments.

Comments

1

Using a dictionary you can access elements like this

structure['parent2']['variable1']

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.