Python How can i read text file like dictionary
<p>I hava a text file like this :</p>

<pre><code>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"
</code></pre>

<p>and i want read this file like dictionary. I mean, when i write imei it should give me 123456789. I'm creating free dictionary and i'm reading this file but its reading like string.</p>

<pre><code>file=open("test.txt","r")

buffer={}
print(type(buffer))
buffer=file.read()
print(type(buffer))

&lt;class 'dict'&gt;
&lt;class 'str'&gt; 
</code></pre>

<p>EDIT : Problem is solved.</p>

<pre><code>import json

with open("test.txt") as f:
    mydict = json.loads('{{ {} }}'.format(f.read()))
</code></pre>

<p>Use the <code>json</code> module; you've already got legal JSON aside from missing the outer curly braces:</p>

<pre><code>import json

with open("test.txt") as f:
    mydict = json.loads('{{ {} }}'.format(f.read()))
</code></pre>

python python-3.x