Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit f755bd5

Browse files
committed
Adding hint for better error messages to readme
1 parent c9e2f00 commit f755bd5

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

README.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,35 @@ solve those problems and hide verything away.
2323
The module can oly be used inside Gatan Microscopy Suite®. The following example shows the
2424
basic usage:
2525
```python
26-
from execdmscript import exec_dmscript
27-
28-
# some script to execute
29-
script = "OKDialog(start_message)"
30-
script_file = "path/to/script.s"
31-
32-
# variables that will be defined for the scripts (and readable later on in python)
33-
sv = {"start_message": "Starting now!"}
34-
# variables the dm-script defines and that should be readable in the python file
35-
rv = {"selected_images": list,
36-
"options": "TagGroup",
37-
"show_message": "nUmBeR"}
38-
39-
with exec_dmscript(script, script_file, readvars=rv, setvars=sv) as script:
40-
print(script["start_message"])
41-
print(script["selected_images"])
42-
print(script["options"])
43-
print(script["show_message"])
44-
45-
# all variables can be accessed via indexing `script` or by using
46-
# `script.synchronized_vars`, note that `script` is also iterable like a dict
26+
import traceback
27+
28+
try:
29+
from execdmscript import exec_dmscript
30+
31+
# some script to execute
32+
script = "OKDialog(start_message)"
33+
script_file = "path/to/script.s"
34+
35+
# variables that will be defined for the scripts (and readable later on in python)
36+
sv = {"start_message": "Starting now!"}
37+
# variables the dm-script defines and that should be readable in the python file
38+
rv = {"selected_images": list,
39+
"options": "TagGroup",
40+
"show_message": "nUmBeR"}
41+
42+
with exec_dmscript(script, script_file, readvars=rv, setvars=sv) as script:
43+
print(script["start_message"])
44+
print(script["selected_images"])
45+
print(script["options"])
46+
print(script["show_message"])
47+
48+
# all variables can be accessed via indexing `script` or by using
49+
# `script.synchronized_vars`, note that `script` is also iterable like a dict
50+
except Exception as e:
51+
# dm-script error messages are very bad, use this for getting the error text and the
52+
# correct traceback
53+
print("Exception: ", e)
54+
traceback.print_exc()
4755
```
4856

4957
Note that the upper script only runs when `execdmscript` is installed in one of the

0 commit comments

Comments
 (0)