title: Conditional module importing in Python
body: <p>I'm just trying out Maya 2017 and seen that they've gone over to <code>PySide2</code>, which is great but all of my tools have <code>import PySide</code> or <code>from PySide import ...</code> in them.</p>
  
  <p>The obvious solution would be to find/replace <code>import PySide</code> to <code>import PySide2</code> and hope everything still works after that, but I'd still like to be able to support older versions of Maya.</p>
  
  <p>My idea was to have a single line solution to find/replace like:</p>
  
  <pre><code>import (PySide2 if "PySide2" in sys.modules else PySide)
  </code></pre>
  
  <p>But this returns: <code>Error: invalid syntax</code>  </p>
  
  <p>Does anyone have any ideas for an alternative to this? I'd like to try and keep it on a single line so it's an easy replacement for when I've got conditions like:</p>
  
  <pre><code>from PySide import QtCore, QtGui
  </code></pre>
  
  <p>Thank you!</p>