SymPy – 8 – visualizzare i risultati (printing) – 2

Continuo da qui, copio qui.

In addition to automatic printing, you can explicitly use any one of the printers by calling the appropriate function.

To get a string form of an expression, use str(expr). This is also the form that is produced by print(expr). String forms are designed to be easy to read, but in a form that is correct Python syntax so that it can be copied and pasted. The str() form of an expression will usually look exactly the same as the expression as you would enter it.

The srepr form of an expression is designed to show the exact form of an expression. It will be discussed more in the Advanced Expression Manipulation section [prossimamente]. To get it, use srepr().

Note: SymPy does not use the Python builtin repr() function for repr printing, because in Python str(list) calls repr() on the elements of the list, and some SymPy functions return lists (such as solve()). Since srepr() is so verbose, it is unlikely that anyone would want it called by default on the output of solve().

The srepr form is mostly useful for understanding how an expression is built internally.

ASCII Pretty Printer
The ASCII pretty printer is accessed from pprint(). If the terminal does not support Unicode, the ASCII printer is used by default. Otherwise, you must pass use_unicode=False.

pprint() prints the output to the screen. If you want the string form, use pretty().

Unicode Pretty Printer
The Unicode pretty printer is also accessed from pprint() and pretty(). If the terminal supports Unicode, it is used automatically. If pprint() is not able to detect that the terminal supports Unicode, you can pass use_unicode=True to force it to use Unicode.

To get the LaTeX form of an expression, use latex().

usando LaTeX Equation Editor poi ottengo

There is also a printer to MathML, called print_mathml(). It must be imported from sympy.printing.mathml.

print_mathml() prints the output. If you want the string, use the function mathml().

The dotprint() function in prints output to dot format, which can be rendered with Graphviz. See the Advanced Expression Manipulation [prossimamente] section for some examples of the output of this printer.


Posta un commento o usa questo indirizzo per il trackback.



Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di

Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: