0

I am working on a server, and I have a set of utilities that I want common to everything 'below' and 'beside' in the directory structure. It looks like this:

Server/
    server.py
    serverutils.py
    games/
        gamehandle.py
        __init__.py

I was wondering how I could import serverutils.py from gamehandle.py. Thanks in advance!

Edit:
I looked at the question here, and the answer I was looking for wasn't there. I solved my problem by placing an empty __init__.py file in the Server/ folder.

Community
  • 1
  • 1
Jerfov2
  • 5,264
  • 5
  • 30
  • 52

1 Answers1

0

Something like :

import os
import imp

serverutils = imp.load_source("serverutils",os.path.join("..",'serverutils.py'))

or directly the full path, because the previous depend on where you launch you script from. The easier in server is to have a param file with the full path.

serverutils = imp.load_source("serverutils",full_path_to_serverutils_script)
Emmanuel Jay
  • 484
  • 3
  • 10
  • That might work, but I figured it out by placing an empty `__init__.py` file in Server/. Thanks though – Jerfov2 Jun 12 '15 at 16:28