cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
hogi
Level XII

Python: get error message?

Python integration in jmp is very useful.

For debugging - when I executing a command in Python  via

Python Submit()

and get a return value -1, indicating that something went wrong. 

Is there a possibility to get the error message?

 

e.g. an automatically updated Python variable, which I could get back to JSL via

 

Python Get(PythonErrorMessage)

 

#myTop10_2022
-> JMP 18 : )

6 REPLIES 6
Craige_Hales
Super User

Re: Python: get error message?

I've been told they are working on it. I was able to build Python code with extra try/except to pass unexpected errors back to JMP as an error message. From Browser Scripting with Python Selenium 

Python Init(); // one-time startup...
// 0: startup 
xrc = Python Execute( {}, {By_ID, By_XPATH, rc},
"\[
try:
    from selenium import webdriver
...
    By_XPATH = By.XPATH
    rc = "ok"
except Exception as e:
    rc = repr(e)
]\"
);

If( xrc != 0 | rc != "ok", Throw( "start up Selenium failed" || Try( ": " || Char( rc ), "" ) ) );

I agree, that wrapper should be built into the execute interface. And, as I recall, there was some sort of failure that it doesn't catch, but it made debugging much more enjoyable.

Craige
hogi
Level XII

Re: Python: get error message?

Amazing - thank you so much!

Definitely worth to get into the next release
@SamGardner?

 

For the time being, I will replace all my Python Submit() with Python Try()
Please not the single additional indentation in he code to match the try in the Python Try function - especially as this implementation of error forwarding doesn't have a chance to react on indentation errors (as well as all the other errors which are detected before executing the code *).
I guess that Jmp team will implement it in a more robust way ...

*) So, if you have an error message like this

hogi_0-1675263255017.png

it could be an indentation error. Beware of using the Reformat Script function



Python Init();

Python Try = Function( {code},
xrc = Python Execute(
		{},
		{rc},
"try:" || code || "\[
	rc = "ok"
except Exception as e:
	rc = repr(e)
]\"
	);
	If( xrc != 0 | rc != "ok",
		Throw( "Python error !
" || Try( Char( rc ), "" ) )
	);
);

Python Try( "
	print(0)" );

Python Try( "
	print(xxx)" );
	
Python Term() 

 

hogi
Level XII

Re: Python: get error message?

Another trick for Python Debugging:

 

Instead of 

Python Submit("\[
Lorem ipsum dolor sit ametERROR IS HERE, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
]\")

split the code off by including it as a package:

Python Submit("
import loremIpsum as li li()
");

Then you can import the same package in parallel into a pythonText.py file and check if all the functions run as expected.

Then JSL debugging can be reduced to the interface part.


Additional benefit: 

You can edit the code of the loremIpsum package in your preferred Python text editor with syntax highlighting and other gimmicks.

SamGardner
Level VII

Re: Python: get error message?

For now, Wrapping the Python call inside a Try( ) is the best option.  This is definitely captured as an issue, and it will require some investigation to see what can be done. 

Re: Python: get error message?

As Craige has indicated, use of try: except: is the best option.  It's also great programming practice to make a habit.  

 

Very soon we will be unveiling JMP 18 in Manchester.  I believe you will be pleasantly surprised.  Significant effort has been put into updating and improving the Python integration. 

 

Stay tuned...

hogi
Level XII

Re: Python: get error message?

Very cool the new smooth integration of Python in Jmp.