cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

concatenating a variable into a python string

emorris1000
Level II

Its been a while since I've really messed with this stuff, but having some issues with the Python Submit function.   Take the following code

 

 

Names Default To Here( 1 );
Python Init();
Python Submit( "\[
str = 'The quick brown fox jumps over the lazy dog';
a = 200;
]\" );
getStr = Python Get( str );
getNum = Python Get( a );
Show( getStr, getNum );
Python Term();

 

 

If I wanted to make the word "fox" a variable I would have thought it was just a matter of concatenating a variable into the string, but for whatever reason I can't seem to break that string?  Maybe it's because it's a list of strings?   I feel like this is an obvious one but for whatever reason I'm missing it.

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User


Re: concatenating a variable into a python string

Maybe something like this?

Names Default To Here( 1 );
fox = "python";
Python Init();
Python Submit( evalinsert("\[
str = 'The quick brown ^fox^ jumps over the lazy dog';
a = 200;
]\") );
getStr = Python Get( str );
getNum = Python Get( a );
Show( getStr, getNum );
Python Term();

View solution in original post

5 REPLIES 5
jthi
Super User


Re: concatenating a variable into a python string

I assume you are not using JMP18 (but it shouldn't matter). I'm not sure what issue you are having? You are sending one string and one numeric value to Python and then printing them in JMP which should work fine.

 

JMP18

jthi_0-1739941643901.png

-Jarmo
pmroz
Super User


Re: concatenating a variable into a python string

Maybe something like this?

Names Default To Here( 1 );
fox = "python";
Python Init();
Python Submit( evalinsert("\[
str = 'The quick brown ^fox^ jumps over the lazy dog';
a = 200;
]\") );
getStr = Python Get( str );
getNum = Python Get( a );
Show( getStr, getNum );
Python Term();
emorris1000
Level II


Re: concatenating a variable into a python string

That appears to do it.  Any idea why it uses the carrat for that as opposed to just escaping with quotes?

txnelson
Super User


Re: concatenating a variable into a python string

EvalInsert is a JMP JSL function that uses ^ as the default delimiter for the insert.  Here is the JMP Scripting Index entry for the description of the function

txnelson_0-1740000175825.png

The substitution of Fox is performed in JMP before being passed to Python

Jim
pmroz
Super User


Re: concatenating a variable into a python string

You could also do it this way:

Names Default To Here( 1 );
fox = "python";
Python Init();
Python Submit( evalinsert("
str = 'The quick brown " || fox || " jumps over the lazy dog';
a = 200;") );
getStr = Python Get( str );
getNum = Python Get( a );
Show( getStr, getNum );
Python Term();

evalinsert offers a cleaner method, IMHO.