-
I'm trying to do something like @pyexec """
import numpy as np
"""
@pyexec "np.array([1,2])" Is this possible and if so how? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Alternatively Btw there is no distinction between single- and multi-line code (unlike PyCall's |
Beta Was this translation helpful? Give feedback.
-
Got it, thanks. May I suggest making an easier-to-read version of this? Seems like putting a bunch of imports at the top of a script or module is pretty typical. What about this?: @pyexec @__MODULE__ """
import numpy as np
""" |
Beta Was this translation helpful? Give feedback.
@pyexec
always runs in a local scope. I think puttingglobal np
at the top of the first call does what you want.Alternatively
pyexec("import numpy as np", @__module__)
works in global scope unless you provide a local scope in the 3rd arg.Btw there is no distinction between single- and multi-line code (unlike PyCall's
py"..."
macro). You probably want@pyeval
for your second call.