Closed jcfr closed 5 years ago
Reviewing related exec
code I found this:
exec('self.filter = sitk.{0}()'.format(json["name"]), globals(), locals())
I am still trying to understand the change with Py3 exec
and the context of execution, but I suppose this line will still work since it does not create a new variable in the local context.
Great fixes!
@jcfr You should have merge access when ready.
Thanks for the review. I will follow up with changes later this evening.
The last one to fix is:
Could it be simplified by simply using:
if v == default:
w.setCurrentIndex(w.count-1)
You can certainly try it as I'm not certain. Looking at the code: https://github.com/SimpleITK/SlicerSimpleFilters/blob/12efaabb0151c270e61bc7a3b3d08ad4c8db8095/SimpleFilters/SimpleFilters.py#L903
v
will be something like self.filter.Ball
( e.g. for a morphological filter ) so the exec
is used to get the value of that "enum".
Related I found this interesting stack overflow Q/A: https://stackoverflow.com/questions/2220699/whats-the-difference-between-eval-exec-and-compile
It sound like eval
can be used if you just want the right hand side of an assignment. For example, this line in questions might be able to be changed into:
itemValue = eval(v)
This might do away with needing to muck with locals
and globals
.
pinging status of this work @jcrf
See https://github.com/SimpleITK/SlicerSimpleFilters/issues/17 and https://discourse.slicer.org/t/simple-filters-module-do-not-have-any-filters-in-latest-nightly-version/6787