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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With