<br><br><div class="gmail_quote">On Fri, Dec 3, 2010 at 2:04 PM, Dan Stromberg <span dir="ltr">&lt;<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
How does one test if a function exists in pypy?<br>
<br>
In CPython 2.x and 3.x, it appears to be sufficient to use:<br>
<br>
   &#39;funcname&#39; in __bultins__<br>
<br>
...but that doesn&#39;t appear to work in pypy 1.4:<br>
<br>
&gt;&gt;&gt;&gt; print &#39;platform_version&#39; in platform<br>
Traceback (most recent call last):<br>
  File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt;<br>
TypeError: &#39;module&#39; object is not iterable<br>
&gt;&gt;&gt;&gt; print &#39;bytes&#39; in __builtins__<br>
Traceback (most recent call last):<br>
  File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt;<br>
TypeError: &#39;module&#39; object is not iterable<br>
&gt;&gt;&gt;&gt;<br>
<br>
TIA!<br>
_______________________________________________<br>
<a href="mailto:pypy-dev@codespeak.net">pypy-dev@codespeak.net</a><br>
<a href="http://codespeak.net/mailman/listinfo/pypy-dev" target="_blank">http://codespeak.net/mailman/listinfo/pypy-dev</a><br>
</blockquote></div><br>That doesn&#39;t work for me on CPython:<div><br></div><div><div>alex@alex-laptop:~$ python</div><div>Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) </div><div>[GCC 4.4.5] on linux2</div><div>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.</div>
<div>&gt;&gt;&gt; &quot;bytes&quot; in __builtins__</div><div>Traceback (most recent call last):</div><div>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;</div><div>TypeError: argument of type &#39;module&#39; is not iterable</div>
<div><br></div><div><br></div><div>You can use `hasattr` to check if a module has an attribute (function).</div><div><br></div><div>Alex</div><br>-- <br>&quot;I disapprove of what you say, but I will defend to the death your right to say it.&quot; -- Voltaire<br>
&quot;The people&#39;s good is the highest law.&quot; -- Cicero<br>&quot;Code can always be simpler than you think, but never as simple as you want&quot; -- Me<br>
</div>