New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
interfacewithpython single line loops not recognizing outside environment #1574
Comments
@jessdtate I can make the "math" error go away by importing math at the script level, so the functions are available automatically (like with the scirun API). Anymore very common modules I can import this way? With the second error, you stumbled on a Python 3 list comprehension/variable scoping in closures/embedded shell/environment problem 😈 . Read these links for explanation (gory details included): inducer/pudb#103 (open issue) There are ugly workarounds where you have to define your own named function, like so:
that does what you want. So I cannot solve this one myself, with the code you gave. I'm open to suggestions. |
It may be a good idea to import the common modules. Since the expanded loop works too, it may not be worth fixing. It will probably work in a script too, I haven't tested that yet. Definitely needs to be documented at least. |
Stale issue message |
@jessdtate Is this in the documentation? |
This issue is stale because it has been open 240 days with no activity. Remove the stale label or comment, or this will be closed in 60 days. |
Description
When using single line loops in InterfaceWithPython, there is problem with using multiple variables. It works if the loop is self contained, ie, [ [i] for i,e in enumerate(V) if e != 0], but if it relies on another variable or imported package it doesn't recognize them, ie, [a[i] for i in b]. These all work in the python console. If the loop is expanded into long form, there are no problems. I suspect this problem and issues #1569 and #1570, are related.
Steps to Reproduce
V = [0, float('nan'), 500 ]
print([ [i,e] for i,e in enumerate(V) if e != 0])
import math
print([i for i,e in enumerate(V) if math.isnan(e)])
a = list(range(0,10))
b = [1, 5, 6,8]
print([ a[i] for i in b])
Expected behavior:
All these lines should work and the output should be:
[[1, nan], [2, 500]]
[1]
[1, 5, 6, 8]
Actual behavior:
returns an error, either 'math' not found, or 'a' not found
Versions
scirun v5.0-beta.F-37-gbc96c5d
os x 10.10 and 10.8
The text was updated successfully, but these errors were encountered: