Get macro file location at runtime

Hi,

I'm new to python scripting in Klayout environment.
My macro (.lym) needs external files (powershell and dll). I want to store them next to the macro file.
Is there a way to access the path of the macro at runtime?

Comments

  • edited October 2021

    Yes, there is.

    In Python this is __file__. In Ruby, it's __FILE__.

    So in Ruby, to address a file called "additional.file" relative to the .lym file you can use:

    File.join(File.dirname(__FILE__), "additional.file")
    

    I Python I'm using:

    os.join(os.dirname(os.realpath(__file__)), "additional.file")
    

    Matthias

  • Thanks ! It's exactly what I was looking for.

Sign In or Register to comment.