Which is more efficient in Python: standard imports or contextual imports?
Question: I apologize in advance if this question seems remedial.

Which would be considered more efficient in Python:

**Standard import**

    
    
    import logging
    
    try:
      ...some code...
    exception Exception, e:
      logging.error(e)
    

...or...

**Contextual import**

    
    
    try:
      ...some code...
    exception Exception, e:
      import logging
      logging.error(e)
    


Answer: Contextual imports are technically more efficient, but I think they can create
other problems.

Later, if you want to add a similar except clause, you now have two places to
maintain the same block of code. You also now have the problem of testing the
exception, to make sure that the first import doesn't cause any unforeseen
issues in your code.

