title: how to pass value of a variable to import statement in python
body: <p>I'm really new to python. <strong>I'm using python&lt;2.7.</strong> I have to import a file whose name I don't know at start. In fact I have to pass the name of file through command prompt, now I have read the name and stored in variable, but I don't know how to pass it to import statement. I'm trying the code </p>
  
  <pre><code>str = sys.argv[lastIndex]
  from "%s" import *,str
  </code></pre>
  
  <p>but it's giving the error </p>
  
  <pre><code>File "IngestDataToMongo.py", line 86
  from "%s" import *,str
          ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>So how to do it. Also is it possible with python &lt;2.7, because for some reasons I can't change the version of Python or install anything where this code is running.</p>