Executing Python via exec() in a BODS Script.

Trying to execute python code in a script with the exec() function. The code executes successfully via python interpreter. But when i try to execute in BODS Script with the exec() function, it doesn’t work.
So the 2 things that come to mind are am I using the correct syntax for exec() and if the python interpreter is installed on the job server. The syntax I am using is exec(‘Z:\ProjectFolder\MyScript.py’, ‘’, 8); The job runs but nothing happens. Is this correct syntax? the next question is to find out if python is installed on the server, I thought that python does get installed with the standard BODS installation, but I could be wrong. Any suggestions on syntax of exec() and python install on job server. Thanks.


brotherbob (BOB member since 2012-04-18)

call Python.exe followed by the path to the script.

very simple function makes my life easier:

$ReturnVar = exec('[$$PythonExePath]','[$$PythonLibPath]\\[$PythonFunction].py [$PythonArgument]',8);

if (index($ReturnVar,'Traceback (most recent call last):',1) > 0 or index($ReturnVar,'SyntaxError',1) > 0)
	begin
		raise_exception( '**PYTHON EXEC ERROR:... ' || $ReturnVar || ' ... *** please checkout script ***'); 
	end

return(substr($ReturnVar,10,990))

jlynn73 :us: (BOB member since 2009-10-27)

Thanks JLynn. Need some clarification w.r.t the two substitution parameters.
$$PythonExePath
$$PythonLibPath
Are these standard subs params?


brotherbob (BOB member since 2012-04-18)

No, those subst are not standard.

If you execute the script without wrapping some error handling around it, it may not always capture the return code. (which is bad)

second argument is a string to optionally be sent into the script, and parsed using sys.argv[1]


jlynn73 :us: (BOB member since 2009-10-27)

Thanks jlynn, was able to execute the python file after deciphering the path to python.exe. The python installed with data services is 2.6 and was under DataQuality folder.

The error handling script also works. However Data Services doesn’t seem to like your return statement i.e. substr($ReturnVar,10,990)); i removed it from the script and it works fine. Thanks once again.


brotherbob (BOB member since 2012-04-18)

Im guessing the return needs a semi colon at the end;

My object library shows 140 uses of this function. :wave:


jlynn73 :us: (BOB member since 2009-10-27)

That’s what I thought and inserted the semi colon but got this error:

in script is not allowed. (BODI-1111243)


brotherbob (BOB member since 2012-04-18)

That is because I have it built as a custom function. :+1:

hence the complaint about the return()


jlynn73 :us: (BOB member since 2009-10-27)

oh ok cool idea. Will do that.

Thanks.

Just out of curiosity do you the output from data services such as excel files, csv files or tables and utilize Pandas for data analysis or machine learning with SciKit Learn?


brotherbob (BOB member since 2012-04-18)

Looks very interesting but not my area of expertise.


jlynn73 :us: (BOB member since 2009-10-27)