Maybe there could be an option to isympy to do something like this. Give a 
file t.py like

# t.py
1 + 1
2 + 2

I can do this:

$ isympy -q < t.py

In [1]: Out[1]: 2

In [2]: Out[2]: 4

In [3]: Do you really want to exit ([y]/n)? 

Exiting ...

That almost works but it doesn't show the input.

You can make a simple Python script to do this e.g.:

# run.py
from sympy import * 
import sys 
filename, = sys.argv[1:] 
with open(filename) as inputfile: 
    for n, line in enumerate(map(str.strip, inputfile)): 
        print('(i%d): %s' % (n, line)) 
        print('(o%d): %s' % (n, eval(line)))

With that you have:

$ python run.py t.py 
(i0): 1 + 1 
(o0): 2 
(i1): 2 + 2 
(o1): 4

--
Oscar
On Tuesday, 25 August 2020 at 01:53:06 UTC+1 [email protected] wrote:

> 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/6ddd576a-97c3-4725-ac3d-4cb4eaa90627n%40googlegroups.com.

Reply via email to