Suppressing output of module calling outside library

后端 未结 4 2126
花落未央
花落未央 2020-12-02 00:01

I have an annoying problem when using machine learning library PyML. PyML uses libsvm to train the SVM classifier. The problem is that libsvm outputs some text to standard o

4条回答
  •  星月不相逢
    2020-12-02 00:54

    I had the same problem and fixed it like that:

    from cStringIO import StringIO
    
    def wrapped_svm_predict(*args):
        """Run :func:`svm_predict` with no *stdout* output."""
        so, sys.stdout = sys.stdout, StringIO()
        ret = svm_predict(*args)
        sys.stdout = so
        return ret
    

提交回复
热议问题