python import module for code in another py file

Viewed 125

Hi I store user defined functions in a separte file my_functions.py. E.g.,

#my_functions.py
def some_func():
    sleep(1)
    print(1)

And the main code in another file main.py:

#main.py
from time import sleep
from my_functions import *

some_func()

When I run main.py, I have error that sleep is not define. It seems things imported from my_functions.py doesn't know about from time import sleep

Should I import time module in my_funcions.py?

I feel confused, cause I thought only some_func is imported, and if I write from time import sleep in my_functions.py, this sentence won't get executed...

And more general advice about how to store user defined functions is appreciated. Thanks

2 Answers
Related