title: Using python dict imported from file in another python file
body: <p>I've the same issue as asked by the OP in <a href="https://stackoverflow.com/questions/2132985/how-to-import-or-include-data-structures-e-g-a-dict-into-a-python-file-from-a">How to import or include data structures (e.g. a dict) into a Python file from a separate file</a>. However for some reason i'm unable to get it working.</p>
  
  <p>My setup is as follows:</p>
  
  <p>file1.py:</p>
  
  <pre><code>TMP_DATA_FILE = {'a':'val1', 'b':'val2'}
  </code></pre>
  
  <p>file2.py:</p>
  
  <pre><code>from file1 import TMP_DATA_FILE
  
  var = 'a'
  print(TMP_DATA_FILE[var])
  </code></pre>
  
  <p>When i do this and run the script from cmd line, it says string indices must be integers.</p>
  
  <p>When i do <code>type(TMP_DATA_FILE)</code>, i get class 'str'. I tried to convert this to dict to be able to use dict operations, but couldn't get it working.</p>
  
  <p>If i do <code>print(TMP_DATA_FILE.get(var))</code>, since i'm developing using PyCharm, it lists dict operations like get(), keys(), items(), fromkeys() etc, however when i run the program from command line it says 'str' object has no attributes 'get'.</p>
  
  <p>When i do <code>print(TMP_DATA_FILE)</code> it just lists 'val1'. It doesn't list 'a', 'b', 'val2'.</p>
  
  <p>However the same script when run from PyCharm works without any issues. It's just when i run the script from command line as a separate interpreter process it gives those errors.</p>
  
  <p>I'm not sure if it's PyCharm that's causing the errors or if i'm doing anything wrong.</p>
  
  <p>Originally i had only one key:value in the dict variable and it worked, when i added new key:value pair that's when it started giving those errors.</p>
  
  <p>I've also tried using <code>ast.literal_eval</code> &amp; <code>eval</code>, neither of them worked. Not sure where i'm going wrong.</p>
  
  <p>Any help would be highly appreciated.</p>
  
  <p>Thanks.</p>