In my Python workflow, I commonly use the -i
flag to open a Python interpreter which first executes the script I am working on, then allows me to interact with it. For example, in test.py
:
#!/usr/bin/env python
print("Hello World")
x=2
When I run python -i test.py
from the command line, I receive the following output:
Hello World!
>>>
Interactive mode is enabled, yet all definitions made in the script are available to me. Typing x
will yield 2
.
Is there an analogous process for Sagemath? I have tried the -c
flag, but the command sage -c "attach('test.sage')"
fails to enter interactive mode after loading the module I am working on.
Ideally there would be a solution simpler that the one outlined which uses expect
, but if that is indeed the best solution, how would one go about using expect
to cause Sagemath to start an interactive session after loading a specific file?