#Functions

23 messages · Page 1 of 1 (latest)

lethal sierra
#

If I make a .py file with a function it, is it possible to access it in another file ? If yes how ?

gaunt root
#

Using an import statement

lethal sierra
gaunt root
#

utils.py:

def some_utility_thing():
    print("Hello from some thing")

main.py:

# You can do it like this:
import utils
utils.some_utility_thing()

# Or like this:
from utils import some_utility_thing
some_utility_thing()
lethal sierra
#

thank you very much

#

I get this error:
No module named 'file_open.py'; 'file_open' is not a package

gaunt root
#

Probably filenames

main moss
#

do you have your file in the same folder?

lethal sierra
#

yes

main moss
#

dont add .py

#

just the name

lethal sierra
#

oh yes thank you

brisk olive
#

try removing '.py' maybe?

lethal sierra
#

i did and it worked

#

but now i cant access the function

main moss
#

wdym

#
function_name()
#

just call like that

lethal sierra
gaunt root
#

Read my example again

#

💀

lethal sierra
#

fuck ur right