>>> from sage.all import *

>>> exec(preparse(r"""
... a = 2^3
... print a
... """))8>>> a8>>> exit> py$a8

or also:

>>> load("some.sage")  #I believe all sage power is available in load() but not 
>>> all in exec(preparse()).



segunda-feira, 13 de Agosto de 2018 às 18:07:41 UTC+1, Emmanuel Charpentier 
escreveu:
>
> Motivation : see this ask.sagemath.org question 
> <https://ask.sagemath.org/question/43258/is-there-a-way-to-start-a-sage-session-from-a-session-of-its-python-interpreter/>
> .
> Tl;dr : I want to call sage from the R reticulate 
> <https://github.com/rstudio/reticulate> package in order to create mixed 
> text/R/Sage documents. 
>
>    - I am aware that Sagetex allows this, at least when using Sage's R in 
>    a \LaTeX document.
>    - But this solution doesn't extend to noweb Markdown documents, which 
>    are more and more in demand (Web pages, ebooks, other interactive gadgets).
>    - I have checked that the \LaTeX--> Markdown/whatever conversion 
>    currently doable with pandoc or similar tools is cumbersome to the extreme 
>    and/or loses a lot of information.
>
> Done so far : when used as the "Python" interpreter, Sage starts a Python 
> session of its own interpreter (i. e. doesn't start the usual IPython 
> session). The various environment variables are correctly defined.
>
> Thanks to Thierry Monteil, I have been able to create this Sage IPython 
> session, with correct initialization (preparsing, imports, etc...). I have 
> checked that this session can access  R objects, and that the R session can 
> access objects created in Sage.
>
> But this is insufficient :
>
>    - The Sage session does not (re-)starts automatically : one has to 
>    explicitly call IPython.embed(). Not a problem when tran manually ; 
>    problematic for the intended use (creating Sage code chunks in a noweb 
>    document).
>    - To get back to R, you have to exit twice : from the IPython session 
>    then from the Python session. Again not a problem in interactive use, 
> again 
>    a serious problem for the intended use.
>
> So the question is : how can one *replace* the Python REPL  with Sage's ? 
> A serious look at $SAGE_ROOT/src/sage/repl/ipython_extension.py wasn't 
> specially enlightening...
>
> Any ideas ?
>
> [ Note that this answer is necessary to the "right" function, but not 
> sufficient : the name of the Python object interfacing Python to the 
> **calling** R session is, unfortunately "r". Which is the standard name 
> we have picked for our **called** R interpreter... So some r-handling 
> will be necessary from reticulate's side. Keeping the distinction between 
> those may be necessary (e. g. : reusing old code...).
> But I feel that asking for a patch has better chances if we "do our 
> homework first", by solving *our* side of the problem *before* asking for 
> help... ]
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to