Set
Set

Reputation: 934

Can't import functions from Python file in the same directory

I created two Python scripts and put them in the same directory:

myfunctions.py

def f(x):
  return x**2

def g(x):
  return x**3

mytest.py

from myfunctions import f, g

print f(2)
print g(3)

This isn't working, how do I get this to work?

It works when the files are in my home directory, but I don't know how to make it work when they're in some other directory.

Upvotes: 1

Views: 1991

Answers (1)

deathangel908
deathangel908

Reputation: 9699

You probably need to have empty __init__.py file in the same directory to mark directory as a module

Upvotes: 2

Related Questions