title: Lexical cast from string to type
body: <p>Recently, I was trying to store and read information from files in Python, and came across a slight problem: I wanted to read type information from text files. Type casting from string to int or to float is quite efficient, but type casting from string to type seems to be another problem. Naturally, I tried something like this:</p>
  
  <pre><code>var_type = type('int')
  </code></pre>
  
  <p>However, <code>type</code> isn't used as a cast but as a mechanism to find the type of the variable, which is actually <code>str</code> here.</p>
  
  <p>I found a way to do it with:</p>
  
  <pre><code>var_type = eval('int')
  </code></pre>
  
  <p>But I generally try to avoid functions/statements like <code>eval</code> or <code>exec</code> where I can. So my question is the following: Is there another pythonic (and more specific) way to cast a string to a type?</p>