title: Importing a dictionary from a module which has its name in a variable
body: <p>I wrote a program which encode all files inside a folder into strings and write it to a pyfile as a dictionary.</p>
  
  <p>The name of the py file to be created is given along with the path, the dictionary is created by adding " = data" to its name. For instance:</p>
  
  <pre><code>pyfilename = "images.py"
  </code></pre>
  
  <p>then the dictionary with the images is written into this file as <code>imagesdata</code>.</p>
  
  <p>Now I need to decode any py file previously encoded in this manner.</p>
  
  <p>I give only the name of the py file in a variable and the program gets all other names from this and imports the correct dictionary from the correct module with the given name. Sample code given below.</p>
  
  <pre><code>name2decode = images.py
  dictname = name2decode + "data"
  </code></pre>
  
  <p>the program should do</p>
  
  <pre><code>from name2decode import dictname
  </code></pre>
  
  <p>where <code>name2decode</code> and <code>dictnames</code> are variables. I tried using the <code>__import__("name2decode.dictname")</code> syntax but for some reason this does not work. Maybe I got the syntax wrong.</p>
  
  <p>How can this be done?</p>