How can I suppress console output when importing packages into RPy2 in Python?

Whenever I run a script to import packages from importinto RPy2 in Python, some extra lines always appear in the console. I inserted in the example below. How can I suppress this behavior?

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.
+3
source share
3 answers

You can temporarily redirect the output stream to a black hole immediately before the spam code.

import sys

class Blackhole(object):

    def write(self, string):
        pass

stdout = sys.stdout
sys.stdout = Blackhole()

function_el_spammo()

sys.stdout = stdout
+6
source

Besides require(tseries, quietly = TRUE)and using sink(), or its Python equivalent, there is also a simple

suppressMessages( library( tseries ))

which i prefer.

+6
source

R script tseries ( , - functio/package),

require(tseries, quietly = TRUE)
+2

Source: https://habr.com/ru/post/1786618/


All Articles