-1

I use this to import a function in 2.7 which works:

def import_x():
    import os
    import imp
    directory = os.path.dirname(os.path.realpath(__file__))
    os.environ['__PYTHON_SYS_PATH_FOR_TESTFOLDER__'] = directory
    fp, pathname, description = imp.find_module('test', [ directory ])
    if fp is not None:
        try:
            x = imp.load_module('test', fp, os.path.realpath(pathname), description)
        finally:
            fp.close()
        return x

test = import_x()

But I struggle to make this work in 3.5. Any idea please?

jpp
  • 159,742
  • 34
  • 281
  • 339
thedude
  • 53
  • 6

1 Answers1

0

Try this instead:

import sys
directory = os.path.dirname(os.path.abspath(sys.argv[0]))

I'm not sure about the specific change, but this seems to work.

jpp
  • 159,742
  • 34
  • 281
  • 339