| 1 | initial version |
When the .show() method of a MixedIntegerLinearProgram prints something, it is usually sent in the standard output of the shell that called your script. So, if the method was called from a script in a terminal, cou can catch it as usually (e.g. with pipelines | or >).
If the command is launched from a ipython shell, it is catched by ipython and printed in the ipython shell. You can access to it as follows:
sage: p = MixedIntegerLinearProgram()
sage: from IPython.utils import io
sage: with io.capture_output() as captured:
....: p.show()
Then you got the result in the captured object:
sage: captured
<IPython.utils.io.CapturedIO at 0xbf0916c>
sage: print captured
Maximization:
Constraints:
Variables:
sage: str(captured)
'Maximization:\n \nConstraints:\nVariables:\n'
| 2 | No.2 Revision |
When the .show() method of a MixedIntegerLinearProgram prints something, it is usually sent in the standard output of the shell that called your script. So, if the method was called from a script in a terminal, cou can catch it as usually (e.g. with pipelines | or >).
If the command is launched from a ipython shell, it is catched by ipython and printed in the ipython shell. You can access to it as follows:
sage: p = MixedIntegerLinearProgram()
sage: from IPython.utils import io
sage: with io.capture_output() as captured:
....: p.show()
Then you got the result in the captured object:
sage: captured
<IPython.utils.io.CapturedIO at 0xbf0916c>
sage: print captured
Maximization:
Constraints:
Variables:
sage: str(captured)
'Maximization:\n \nConstraints:\nVariables:\n'
It both works on the sage command line and in the notebook.
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.