You can put code in a .py file and use %run in IPython or the notebook to run it. Or in pure Python you can add it to a function, import the file, and run the function (using a function for this case is recommended because while Python's 'import' will run the code in the body of the file, it will only import a module once and cache it after that).
Aaron Meurer On Mon, Aug 24, 2020 at 6:36 PM [email protected] <[email protected]> wrote: > > Maxima and Maple can batch-execute a text file of commands, showing input > interspersed with output: > > $ maxima -b t.mac > Maxima 5.44.0 http://maxima.sourceforge.net > using Lisp CLISP 2.49+ (2010-07-17) > Distributed under the GNU Public License. See the file COPYING. > Dedicated to the memory of William Schelter. > The function bug_report() provides bug reporting information. > (%i1) batch("t.mac") > > read and interpret /t.mac > (%i2) 1+2 > (%o2) 3 > (%i3) 2+3 > (%o3) 5 > (%o4) /t.mac > > $ > > This is often my preferred method of interacting. Mathematica can't. Sympy > can't as far as I know because Python doesn't work like that in batch mode > from the command line, as far as I know. For Sympy, to get the effect I want, > I have to enter the input lines as individual cells in a Jupyter notebook. If > I then need to copy paste the cells to another notebook, I can't, because > JupyterLab lacks that functionality. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/d4913e80-156a-48fa-914b-27b16049b71cn%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LnrePvJYN_4wUrnqKn2K9H75V0Quy%3DPnX3BKPeZPb35A%40mail.gmail.com.
