Basically, I want to know if importing standard libraries in every module is better/worse than just importing the standard module once in a module and reusing it in other modules. In other words, I wanted to know if there is any speed/performance difference between the following two codes:
"""
One way - Just importing time module only once
"""
# /usr/bin/python
# mytime.py
import time
def get_time():
return time.time()
# /usr/bin/python
# usingtime.py
import mytime
print (mytime.time() - mytime.time.time())
"""
Another way - importing time module as needed
"""
# /usr/bin/python
# mytime.py
import time
def get_time():
return time.time()
# /usr/bin/python
# usingtime.py
import time
import mytime
print (mytime.time() - time.time())
Which code is better? or does it really matter?