2

I know that I can use the following magic functions in Jupyter to write the content of a cell to a given file:

%%writefile ./file.txt

I wrote my own magic functions based on this writefile function. The question is how can I use it but in .py file, not jupyter notebook? Because in .py we don't have cells.

jujus
  • 149
  • 7
  • The problem isn't missing cells, it's the missing Jupyter runtime environment. You can import your own code into other modules directly or wrap the execution of other code by various means. You will have to show us what you have written and how you want to use it. – Jan Wilamowski May 19 '22 at 05:41
  • Jan is correct. We'd need more information. Your magic function may be pure Python aside from some parts. We cannot tell. I'll will add that writing a file is something basic Python does and so you may just want to review the ways some people do that and not bother with converting this magic function you have. – Wayne May 19 '22 at 21:22

1 Answers1

0

not sure if this will help but it seems someone else wanted to do something kind of similar (but still using .ipynb files), here's the link. However, I do not think its possible to call magic functions outside a notebook and the Ipython kernel. The python interpreter does not recognize the magic function syntax, read more regarding this in the Ipython docs.

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32569426) – n4321d Aug 31 '22 at 02:55
  • Noted, thanks. The aim was to be helpful :D. – abdulla421 Oct 17 '22 at 16:10