How to split dictionary keys into multiple separate keys in python?
<p>In Python I am using the RRDTool Python wrapper to store and read values into / from a RRD-Database.</p>

<p>The RRDTool for Python is a wrapper for the C-based source / command-line utility of rrdtool. </p>

<p>After creating a database I want to read out it's header using the python command: </p>

<pre><code>header_info = rrdtool.info('database_file_name.rrd') 
</code></pre>

<p>which is equal to the command line utility:</p>

<pre><code>rrdtool info database_file_name.rd
</code></pre>

<p>and which would print header-infos like that:</p>

<pre><code>filename = "database_file_name.rrd"
rrd_version = 5
...
ds[datasource_identifier_1].index = 0
ds[datasource_identifier_1].type = "GAUGE"
...
ds[datasource_identifier_2].index = 1
ds[datasource_identifier_2].type = "GAUGE"
...
</code></pre>

<p>In python the output of the command line tool is wrapped inside a single big dictionary with the following schema:</p>

<pre><code>key: value
"filename" : "database_file_name.rrd"
"ds[datasource_identifier_1].index" : "0"
"ds[datasource_identifier_2].type" : "GAUGE"
</code></pre>

<p>I am now trying to figure out how to split up that dictionary so that I could access it like that:</p>

<pre><code>index = dictionary["ds"]["datasource_identifier_1"]["index"]
</code></pre>

<p>But I do not have a clue how to do that using python. I would guess this can be done with iteration over the original dictionary and split up those keys using "[","]" and "." as triggers and create a new dictionary then. </p>

<p>How can I do that in Python?</p>