Import homemade functions into MantidWorkbench script

This is probably quite a generic python question, but trying to figure it out myself led me down an endless rabbit hole…

I have created some useful functions (function1, function2, etc) in a file myFunctions.py which I have saved in the default mantidWorkbench directory (in my case /SNS/users/mguthrie/MantidWorkbench/).

I then create a new script from which I am trying to import, say, function1. So I added:

from myFunctions import function1

But, I am getting “ImportError: cannot import name function1”

Can anyone help with this?

Thanks!

Hi,

I am able to get:
from FileInSameDirectory import function1
working in MantidWorkbench 4.2

if Python couldn’t find the other file it would likely say ImportError: No module named...,
but ImportError: cannot import name... suggests it can find your file just not the function.
Annoyingly, the first thing to check is that function1 is spelt correctly.

I assume your rabbit hole may have involved some Python 3 stuff that involved either writing:
from .myFunctions import function1
or adding an empty file called __init__.py to the same directory.

If you’re able to send the files involved to me at daniel.murphy@stfc.ac.uk then I can have a go trying to make them work!

Mantid Support