Skip to main content
Solved

Dynamic listing of parameter names

  • July 31, 2023
  • 2 replies
  • 34 views

dustin
Influencer
Forum|alt.badge.img+31

One thing I prefer to do when building a new FME tool is to log the input parameters in a startup python script in order to facilitate debugging when things go wrong. A sample of the code I use is below.

import fmeobjects
 
fmeobjects.FMELogFile().logMessageString("Input parameter 1: ") + FME_MacroValues["parameter1"], fmeobjects.FME_INFORM)
fmeobjects.FMELogFile().logMessageString("Input parameter 2: ") + FME_MacroValues["parameter2"], fmeobjects.FME_INFORM)

This has worked great for a long time, however it's cumbersome because I need to manually enter the names of the parameters. I'm curious if there is a method for returning the names of parameters dynamically in the startup python script, and then loop through them to include in the log file. If this is possible, I could keep my startup script the same between all tools and simply copy it into new tools without having to modify.

 

Best answer by saraatsafe

Hi @dustin​, 

You can try iterating through macrovalues and excluding most of the irrelevant FME-specific values. For example: 

import fme, fmeobjects
 
for k, v in fme.macroValues.items():
    if k.startswith("FME_"):
        continue
    fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")

Hope this helps!

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

saraatsafe
Safer
Forum|alt.badge.img+11
  • Safer
  • 147 replies
  • Best Answer
  • July 31, 2023

Hi @dustin​, 

You can try iterating through macrovalues and excluding most of the irrelevant FME-specific values. For example: 

import fme, fmeobjects
 
for k, v in fme.macroValues.items():
    if k.startswith("FME_"):
        continue
    fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")

Hope this helps!


dustin
Influencer
Forum|alt.badge.img+31
  • Author
  • Influencer
  • 629 replies
  • July 31, 2023

Hi @dustin​, 

You can try iterating through macrovalues and excluding most of the irrelevant FME-specific values. For example: 

import fme, fmeobjects
 
for k, v in fme.macroValues.items():
    if k.startswith("FME_"):
        continue
    fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")

Hope this helps!

@saraatsafe​ 

 

Thank you! Brilliant! This is what I came up with:

import fme,fmeobjects
fmeobjects.FMELogFile().logMessageString("---------\n------------------\n---------------------------\n------------------------------------\n", fmeobjects.FME_INFORM)
 
for k,v in sorted(fme.macroValues.items()):
    if k.startswith("1_"):
        fmeobjects.FMELogFile().logMessageString(f"{k}: {v}")
        
fmeobjects.FMELogFile().logMessageString("------------------------------------\n---------------------------\n------------------\n---------\n", fmeobjects.FME_INFORM)

I'll just need to make sure I prefix my  parameter identifiers with "1_". And the result:

image