<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[boost + python + PyErr_Print umleiten]]></title><description><![CDATA[<p>Hey @all,</p>
<p>weiß jemand ob es mit boost python irgendwie möglich ist die Ausgabe von &quot;PyErr_Print()&quot; auf der Konsole zu unterdrücken, und stattdessen einen std::string oder ähnliches zurück zu bekommen?</p>
<p>Folgender Tipp: <a href="http://www.c-plusplus.net/forum/viewtopic-var-p-is-1495461.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-p-is-1495461.html</a></p>
<p>.filmor schrieb:</p>
<blockquote>
<pre><code class="language-cpp">catch (bp::error_already_set const&amp;)
{
    bp::str blubb = bp::import(&quot;sys&quot;).attr(&quot;stderr&quot;).attr(&quot;data&quot;);
// mit blubb rumspielen, zB zu std::string konvertieren oder sowas
}
</code></pre>
</blockquote>
<p>funktioniert leider nicht, da bekomme ich folgenden Fehler:</p>
<pre><code>error: conversion from `boost::python::api::proxy&lt;boost::python::api::attribute_policies&gt;' to non-scalar type `boost::python::str' requested
</code></pre>
<p>Das ganze wäre deswegen weil ich das ganze für eine MessageBox brauchen würde (GUI Applikation), somit brauche ich eben keine Ausgabe auf eine Konsole:</p>
<pre><code class="language-cpp">try {
.
.
.
}catch(PythonFehler &amp;e) {
    // PyErr_Print();          // &lt;------ Die Ausgabe soll stattdessen in die MessageBox
    MessageBox(&quot;HIER KOMMT DER PYTHON FEHLER (BACKTRACE) REIN&quot;);
}
</code></pre>
<p>Habe bei mir folgendes laufen:</p>
<ul>
<li>Python 2.5.2</li>
<li>Boost 1_35_0</li>
<li>mingw32-make 3.80</li>
</ul>
<p>Vielen lieben Dank im Voraus<br />
Lg _freeze_</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/211424/boost-python-pyerr_print-umleiten</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 06:26:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/211424.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Apr 2008 05:21:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost + python + PyErr_Print umleiten on Wed, 23 Apr 2008 05:21:16 GMT]]></title><description><![CDATA[<p>Hey @all,</p>
<p>weiß jemand ob es mit boost python irgendwie möglich ist die Ausgabe von &quot;PyErr_Print()&quot; auf der Konsole zu unterdrücken, und stattdessen einen std::string oder ähnliches zurück zu bekommen?</p>
<p>Folgender Tipp: <a href="http://www.c-plusplus.net/forum/viewtopic-var-p-is-1495461.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-p-is-1495461.html</a></p>
<p>.filmor schrieb:</p>
<blockquote>
<pre><code class="language-cpp">catch (bp::error_already_set const&amp;)
{
    bp::str blubb = bp::import(&quot;sys&quot;).attr(&quot;stderr&quot;).attr(&quot;data&quot;);
// mit blubb rumspielen, zB zu std::string konvertieren oder sowas
}
</code></pre>
</blockquote>
<p>funktioniert leider nicht, da bekomme ich folgenden Fehler:</p>
<pre><code>error: conversion from `boost::python::api::proxy&lt;boost::python::api::attribute_policies&gt;' to non-scalar type `boost::python::str' requested
</code></pre>
<p>Das ganze wäre deswegen weil ich das ganze für eine MessageBox brauchen würde (GUI Applikation), somit brauche ich eben keine Ausgabe auf eine Konsole:</p>
<pre><code class="language-cpp">try {
.
.
.
}catch(PythonFehler &amp;e) {
    // PyErr_Print();          // &lt;------ Die Ausgabe soll stattdessen in die MessageBox
    MessageBox(&quot;HIER KOMMT DER PYTHON FEHLER (BACKTRACE) REIN&quot;);
}
</code></pre>
<p>Habe bei mir folgendes laufen:</p>
<ul>
<li>Python 2.5.2</li>
<li>Boost 1_35_0</li>
<li>mingw32-make 3.80</li>
</ul>
<p>Vielen lieben Dank im Voraus<br />
Lg _freeze_</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1496560</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1496560</guid><dc:creator><![CDATA[_freeze_]]></dc:creator><pubDate>Wed, 23 Apr 2008 05:21:16 GMT</pubDate></item><item><title><![CDATA[Reply to boost + python + PyErr_Print umleiten on Wed, 23 Apr 2008 14:30:24 GMT]]></title><description><![CDATA[<p>Du hast meinen Tipp aber ganz schön aus dem Kontext gerissen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> (ändert nichts an dem Fehler, da müsste wohl noch ein as_string oder sowas hin, müsstest du in der Doku nachsehen).</p>
<p>Wie wärs hiermit?</p>
<pre><code class="language-cpp">class StderrCatcher
{
public:
    StderrCatcher (std::string&amp; ref) : _data (ref)
    {
       bp::object new_stream;
       new_stream.attr (&quot;write&quot;) = bp::def (StderrCatcher::write);
       bp::object sys = bp::import (&quot;sys&quot;);
       _old_stream = sys.attr (&quot;stderr&quot;);
       sys.attr (&quot;stderr&quot;) = new_stream;
    }

    ~StderrCatcher () { bp::import (&quot;sys&quot;).attr (&quot;stderr&quot;) = _old_stream; }

    void write (std::string const&amp; str) { _data += str; }

private:
    std::string&amp; _data;
    bp::object _old_stream;
};

/// Benutzen dann:
catch (bla)
{
    std::string err_msg;

    {
        StderrCatcher catcher (err_msg);
        PyErr_Print ();
    }
 // err_msg verwenden
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1496949</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1496949</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Wed, 23 Apr 2008 14:30:24 GMT</pubDate></item><item><title><![CDATA[Reply to boost + python + PyErr_Print umleiten on Wed, 23 Apr 2008 18:45:56 GMT]]></title><description><![CDATA[<p>Danke vielmals,</p>
<p>werde ich dann gleich mal probieren.</p>
<p>.filmor schrieb:</p>
<blockquote>
<p>Du hast meinen Tipp aber ganz schön aus dem Kontext gerissen</p>
</blockquote>
<p>Wie meinst Du das? Habe ich was falsch verstanden?</p>
<p>Lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1497109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1497109</guid><dc:creator><![CDATA[_freeze_]]></dc:creator><pubDate>Wed, 23 Apr 2008 18:45:56 GMT</pubDate></item><item><title><![CDATA[Reply to boost + python + PyErr_Print umleiten on Wed, 23 Apr 2008 20:16:34 GMT]]></title><description><![CDATA[<p><em>freeze</em> schrieb:</p>
<blockquote>
<p>Danke vielmals,</p>
<p>werde ich dann gleich mal probieren.</p>
</blockquote>
<p>Sag mir dann auch, ob's funzt. Sowas kann man bestimmt nochmal gebrauchen. Bin aber ganz zuversichtlich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p><em>freeze</em> schrieb:</p>
<blockquote>
<p>.filmor schrieb:</p>
<blockquote>
<p>Du hast meinen Tipp aber ganz schön aus dem Kontext gerissen</p>
</blockquote>
<p>Wie meinst Du das? Habe ich was falsch verstanden?</p>
</blockquote>
<p>Naja, das funktioniert so alles nur, wenn du den StdoutCatcher aus dem Link, den ich dir gegeben habe benutzt. Die Verbindung wahr vielleicht unklar.<br />
Verstehst du den Code?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1497149</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1497149</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Wed, 23 Apr 2008 20:16:34 GMT</pubDate></item></channel></rss>