-1

With python 3.7 I am trying to import functions which are defined in a module file. This module file is named mytool.py and contains

def foo():
    return 42

Following the solution I found on this page I have the main code mycode.py as follows:

from . import mytool

which yields an error

Traceback (most recent call last):
  File "mycode.py", line 3, in <module>
    from . import mytool
ImportError: attempted relative import with no known parent package

Is there a way to fix this as short and concise as possible, without having to add to sys.path?

Alex
  • 41,580
  • 88
  • 260
  • 469

1 Answers1

3

from mytool import foo

or

import mytool

Dev Yego
  • 539
  • 2
  • 12