The method is import osmore efficient in terms of runtime.
If we import the whole module:
import os
def list():
print(os.listdir('.'))
it runs in 0.074s, but when importing only one method:
from os import listdir
def list():
print(listdir('.'))
then it takes 0.076 s.
Here I used a module timeitto perform the above functions.
source
share