How should you import things in Python

Instead of from time import sleep, you could use import time. Just use the entire thing, not just the sleep part of it. Gets the job done just as well, but you can use more features.

But if you do that you can’t use sleep, you have to use time.sleep

2 Likes

True, that is faster, but you can’t use the rest of the time module.

why not?

from time import sleep, time, timeit
2 Likes

Plus, if you do it that way, you can do fun things like this:

from time import (
    sleep as slp,
    time as tm,
    timeit as ti
)
3 Likes

Which I don’t recommend because you shouldn’t abbreviate things because it makes stuff harder to understand.

2 Likes

I would think this would be more efficient than importing the entire thing, especially if you were trying to import a module of immense size.

2 Likes

or you can just do

from time import * # fyi * means everything so yes i love it :3
print('Hello world')
sleep(5)

works for me, how about yall?

Inefficient:

2 Likes