Bug: define_macro & embed doesn't work as expected inside a method vs __main__
See original GitHub issueIf I have a macro inside a function doesn’t work as expected, the same is working fine on __main__
condition. Why?
Define Macro in function throws an error…!
import IPython as ipy
from IPython.terminal.interactiveshell import TerminalInteractiveShell
def run():
shell = TerminalInteractiveShell.instance()
shell.define_macro('foo', """a,b=10,20""")
ipy.embed(display_banner=False)
if __name__ == "__main__":
run()
⋊> ~/c/i/i/ipycli on master ⨯ ipython test
In [1]: foo
Out[1]: IPython.macro.Macro('a,b=10,20\n')
In [2]: a,b
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-2fbdd1b4fa70> in <module>
----> 1 a,b
NameError: name 'a' is not defined
Define Macro in main works fine…!
import IPython as ipy
from IPython.terminal.interactiveshell import TerminalInteractiveShell
if __name__ == "__main__":
shell = TerminalInteractiveShell.instance()
shell.define_macro('foo', """a,b=10,20""")
ipy.embed(display_banner=False)
⋊> ~/c/i/i/ipycli on master ⨯ ipython test
In [1]: foo
In [2]: a,b
Out[2]: (10, 20)
IPython version 7.14.0 OS: macOS Catalina Terminal: iTerm2 version 3.3.9
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Indent function doesn't work as expected when indenting tables
To workaround this issue you can use the User Macro defined in this comment and embed the table into nested 'indent' macros.
Read more >c preprocessor - #define macro for debug printing in C?
Basically, it means that all of your code is checked by the compiler every time you compile - whether for release or debugging....
Read more >Macros - Scala 3
Defining a macro and using it in a single project It is possible to define macros and use them in the same project...
Read more >std::embed - All the Details - The Pasture
The argument that storing binary data easily in a programming language – whose fundamental job is to interpret binary data to do its...
Read more >Groovy Language Documentation
When a method (whether implemented in Java or Groovy) expects a java.lang. ... List , as Groovy doesn't define its own collection classes....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Got the solution, after defining the I need assign manually when I am calling the embed from function
x, y = shell.user_ns['x'], shell.user_ns['y']
beforeipy.embed(display_banner=False)
@Carreau updated the question with proper code, please help @minrk @takluyver