title: Use a python dictionary for "switch" on datatype
body: <p>I’m trying to write a “switch” dictionary in python.  I want to be able to read in data from a text file and do different things depending on it’s datatype.  So for example if I read in a string I want to compare it to another string.  Or if I read in a float I want to do some operations with it.  It’s a data cleaning operation for a machine learning program.  </p>
  
  <p>I could probably do this with an If…Else statement, but since I could conceivably have something for every datatype, I’d rather do it cleaner. </p>
  
  <p>I’m using the following code:</p>
  
  <pre><code>varX = 2.0
  switchDict = {"bool": "boolean", "int": "integer","float": "floatType",
                 "str": "string"}
  
  switchDict[str(type(varX))]()
  
  def boolean():
      print("You have a boolean" )
  
  def integer():
      print("You have an integer")
  
  def floatType():
      print("You have a float")
  
  def string():
      print("You have a string”)
  </code></pre>
  
  <p>It returns:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Gower71/Switch.py", line 5, in &lt;module&gt;
  switchDict[str(type(varX))]()
  KeyError: "&lt;class ‘float'&gt;"
  </code></pre>
  
  <p>If I change the switchDict lines to:</p>
  
  <pre><code>switchDict = {bool: "boolean", int: "integer", float: "floatType", str: "string"}
  switchDict[type(varX)]()
  </code></pre>
  
  <p>It returns:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Gower71/Switch.py", line 5, in &lt;module&gt;
      switchDict[type(varX)]()
  TypeError: 'str' object is not callable
  </code></pre>
  
  <p>Is there a way to switch on type like this??</p>