I have a special Class that capture and process the logs of a given algorithm. This looks like this
report = Report2File(logger,"./path")
report.start()
solveProblem()
report.stop()
del report
I would like to be event more lazy and write only
%%report "./path"
solveProblem()
The creation of such Magic Cell seams easy at first
UPDATED:
@magics_class
class MyMagics(Magics):
@cell_magic
def cmagic(self, line, cell):
"my cell magic"
self.before()
exec(cell)
self.after()
return line, cell
def before(self):
do stuff ...
def after(self):
do stuff ...
ip = get_ipython()
ip.register_magics(MyMagics)
However I get two issues:
- I don't know how to pass the logger object to my magic
- Jupyter keep telling me that the MyMagics module is not an ipython extension
Partial Answer
this talk gives me the answer to 2.
Instead of
ip = get_ipython()
ip.register_magics(MyMagics)
The correct way to register a Magic is the following
def load_ipython_extension(ip):
ip.register_magics(MyMagics)
def unload_ipython_extension(ip):
pass