Forums

Does code run at PA?

That's probably answered elsewhere, but I could not found it. Usually I also test code locally on different machines having assets in different paths. So far I've did this to switch case:

host = socket.gethostname()
if host == "hansel-livetask" :
  path = "xyz"
elif host == "glenn-liveconsole" :
  path = "xyz"
## and so on

This got longer and longer over time. Is there a future proof way to implement this?

What are you trying to accomplish with this?

Let's say I'd like to composite 2 images. One is generated with live data by code, the other is always the same logo. On all machines the logo is in different paths. So I want to map paths onto machines.

Makes sense?

I think your best bet would be to place the files in the same place relative to a known file and then use os.path hackery to find them again. Like this:

some_directory
      |- image_getter.py
      |- images
             |- image1
             |- image2

in image_getter, you can then use:

os.path.abspath(os.path.join(os.path.dirname(__file__), 'images'))

to find the images directory.

Is that kind-of the thing you're looking for?

Thanks, looks better and even eliminates that ever growing list of machines. Should pay more attention to the double underscore features of python.