Comment remplacer la magie jupyter-notebook par un script python
Solution du problème
Vous pouvez exécuter la magie de ligne IPython en utilisant IPython interactiveshell
:
from IPython.terminal.interactiveshell import TerminalInteractiveShell
shell:TerminalInteractiveShell = TerminalInteractiveShell.instance()
shell.run_line_magic("load_ext","sql")
shell.run_line_magic("config","SqlMagic.displaycon=False")
# or shell.config["SqlMagic"]={'displaycon': False}
run_line_magic(magic_name, line_after_magic)
vous pouvez même lancer un cd
shell.run_line_magic("cd","..")
Et ça marchera.
Cependant, il y a une magie qui ne fonctionne pas TerminalInteractiveShell
car elle ne peut pas évaluer votre code (alias, page,...).
Commentaires
Enregistrer un commentaire