Syntax of importing multiple classes from a module
<p>I'm reading some code which contains the following import statement:</p>

<pre><code>from threading import local as thread_local, Event, Thread
</code></pre>

<p>At first this syntax puzzled me, but I think it is equivalent to:</p>

<pre><code>from threading import local as thread_local
from threading import Event
from threading import Thread
</code></pre>

<p>Can anyone confirm whether this is the case?</p>

<p>You can check this on the official documentation. Here's the <a href="https://docs.python.org/3/reference/simple_stmts.html#import" rel="nofollow">documentation for the <code>import</code> syntax</a>:</p>

<blockquote>
<pre><code>import_stmt     ::=  "import" module ["as" name] ( "," module ["as" name] )*
                     | "from" relative_module "import" identifier ["as" name]
                     ( "," identifier ["as" name] )*
                     | "from" relative_module "import" "(" identifier ["as" name]
                     ( "," identifier ["as" name] )* [","] ")"
                     | "from" module "import" "*"
module          ::=  (identifier ".")* identifier
relative_module ::=  "."* module | "."+
name            ::=  identifier
</code></pre>
</blockquote>

<p>Note how you always have the <code>import module ["as" name]</code> and <code>identifier ["as" name]</code>, including in the list definition:</p>

<pre><code>( "," identifier ["as" name] )* 
</code></pre>

<p>This means a comma <code>,</code> followed by an identifier, optionally assigned with <code>as</code> to a name and the <code>)*</code> means "this group can be repeated zero or more times, which includes the example you provided.</p>

<p>This is also explained on the same page a bit later on:</p>

<blockquote>
  <p>The <code>from</code> form uses a slightly more complex process:</p>
  
  <ol>
  <li>find the module specified in the <code>from</code> clause, loading and initializing it if necessary;</li>
  <li>for each of the identifiers specified in the import clauses:
  
  <ol>
  <li>check if the imported module has an attribute by that name</li>
  <li>if not, attempt to import a submodule with that name and then check the imported module again for that attribute</li>
  <li>if the attribute is not found, <code>ImportError</code> is raised.</li>
  <li>otherwise, <strong>a reference to that value is stored in the local namespace, using the name in the <code>as</code> clause if it is present, otherwise
  using the attribute name</strong></li>
  </ol></li>
  </ol>
</blockquote>

python