Wie kann ich unterdrücke die auf der Konsole, wenn Pakete in RPy2 in Python zu importieren?
Frage
Jedes Mal, wenn ich ein Skript importieren Pakete mit import
in RPy2 in Python laufen, gibt es immer einige zusätzliche Zeilen in der Konsole auftauchen. Ich klebte in einem Beispiel unten. Wie kann ich unterdrücken, dass das Verhalten?
CookieJar:r cookies$ python script.py
‘tseries’ version: 0.10-24
‘tseries’ is a package for time series analysis and computational
finance.
See ‘library(help="tseries")’ for details.
Lösung
You could temporarily redirect the output stream to a blackhole just before the spammy peice of code.
import sys
class Blackhole(object):
def write(self, string):
pass
stdout = sys.stdout
sys.stdout = Blackhole()
function_el_spammo()
sys.stdout = stdout
Andere Tipps
Besides require(tseries, quietly = TRUE)
and using sink()
, or its Python equivalent, there is also the simple
suppressMessages( library( tseries ))
which I prefer.
In your R script, I would preload the tseries
package (just in case if its called by some other functio/package) using
require(tseries, quietly = TRUE)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow