Page 1 of 1

Passing arguments to a python function call

Posted: Thu Jul 28, 2016 10:37 am
by wandadars

I'm trying to call a python function from within a Tecplot macrofunction.

The main goal is to call a python function and pass it the loop indices for a nested loop that I have, and have the python script go to a file and retrieve an entry based on those two parameters i.e. value = my_python_script(loop_1_index,loop_2_index)

I'm trying to put something together based on the following forum posts:

The relevant part of my macrofunction code is:

Code: Select all

#Get the mean value

  COMMAND='RUNPYFUNCTION MODULE="compute_fluctuation" FUNCTION="compute_fluctuation_module" ARGUMENTS="|VarName|,|TimeLoopIndex|,|LOOP|"'

My Python script looks like:

Code: Select all

def compute_fluctuation_module(var_name,loop_index,slice_index)
   import TecUtils
   import TecVals

   #Locate mean value from users inputs
   input_file_name = var_name + "_"+loop_index+".txt"
   line_count = 1
   with open(input_file_name,'r') as f:
      for Line in f:
         if line_count == slice_index):
            mean_value = f.readline()
            line_count = line_count + 1
            {p_prime} = {p} - 100000'
   equation_string = "{"+var_name+"_prime} = "+"{"+var_name+"} - "+mean_value


Tecplot complains that: COMMAND='RUNPYFUNCTION MODULE="compute_fluctuation" FUNCTION="compute_fluctuation_module" ARGUMENTS="|VarName|,|TimeLoopIndex|,|LOOP|"' is not a valid command.

What would be the best way to structure a call to a python script from within my macrofunction such that I can pass it parameters? I'm also not 100% sure that I structured the RUNPYFUNCTION MODULE command correctly. The double and single quotes that are used in the examples shown in the forum posts that were linked to earlier are confusing i.e. I don't always see a set of matching open and close quotations around the commands.

Thank you,
Chris Neal

Re: Passing arguments to a python function call

Posted: Sun Jan 06, 2019 1:34 am
by teddy26

If I correctly speaking python uses mechanism of call by object sometimes we call it call by sharing in which we pass argument like integers,strings,function etc.What i'm saying this is correct or not??I think error is generate just because of coding which isn't in correct way or the way which we pass argument.
I think if you are not satisfied with me then I'm not getting your point correctly.
Please check by google.

Python Compiler