title: Python import from user input or command line argument
body: <p>I want one module to import data from another, but I don't want to hard code the name of the other module. I have attempted using <code>sys.argv</code>, as in:</p>
  
  <pre><code>from sys import argv
  from argv[1] import database
  </code></pre>
  
  <p>but this gives me <code>invalid syntax</code> under <code>argv[1]</code>. I have also tried raw_input, as in:</p>
  
  <pre><code>module = raw_input("Enter module name: ")
  from module import database
  </code></pre>
  
  <p>This results in <code>ImportError: No module named module</code>. I checked that this is not due to the name being module. Other variable names have the same result.
  The name of the variable database will always be the same. I have successfully imported this variable by importing from the name of the module, but I would like this code to handle cases where the module name is different, as I can then use more than one, and the user is not obliged to use the same module name every time. Is there a way to do this? All the other questions I have seen do not address this specific issue, and I have not found any information in Python's help module either.</p>