Python import module for code in another py file

Hi I am storing user-defined functions in a separte file my_functions.py. For instance.

#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 start main.py, I have an error that sleepdoes not detect. It seems that the things imported from my_functions.pydo not know aboutfrom time import sleep

Should I import a time module in my_funcions.py?

I feel embarrassed because I thought that it was imported only some_func, and if I write from time import sleepin my_functions.py, this sentence will not be fulfilled ...

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

+4
source share
2
from time import sleep
#my_functions.py
def some_func():
    sleep(1)
    print(1)

/, .

+1

, my_functions.py. , , :

: (1) ; (2) (, ). () . from from (1) , (2) . https://docs.python.org/2.0/ref/import.html

PEP008

+1

All Articles