- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
concatenating a variable into a python string
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
The substitution of Fox is performed in JMP before being passed to Python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.