<br><br><div class="gmail_quote">On Fri, Dec 3, 2010 at 2:04 PM, Dan Stromberg <span dir="ltr"><<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>></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>
'funcname' in __bultins__<br>
<br>
...but that doesn't appear to work in pypy 1.4:<br>
<br>
>>>> print 'platform_version' in platform<br>
Traceback (most recent call last):<br>
File "<console>", line 1, in <module><br>
TypeError: 'module' object is not iterable<br>
>>>> print 'bytes' in __builtins__<br>
Traceback (most recent call last):<br>
File "<console>", line 1, in <module><br>
TypeError: 'module' object is not iterable<br>
>>>><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'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 "help", "copyright", "credits" or "license" for more information.</div>
<div>>>> "bytes" in __builtins__</div><div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div><div>TypeError: argument of type 'module' 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>"I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire<br>
"The people's good is the highest law." -- Cicero<br>"Code can always be simpler than you think, but never as simple as you want" -- Me<br>
</div>