[pypy-dev] Testing if a function exists?
Maciej Fijalkowski
fijall at gmail.com
Fri Dec 3 20:37:44 CET 2010
Use:
import __builtin__
and treat it as module. __builtins__ is an ugly hack that is sometimes
a dict and sometimes a module and pypy has different corner cases.
__builtin__ will always work
On Fri, Dec 3, 2010 at 9:13 PM, Leonardo Santagada <santagada at gmail.com> wrote:
> (I'm guessing but) In python 2.5 modules are not iterable, you can use
> getattr for the same effect.
>
> On Fri, Dec 3, 2010 at 5:04 PM, Dan Stromberg <drsalists at gmail.com> wrote:
>> How does one test if a function exists in pypy?
>>
>> In CPython 2.x and 3.x, it appears to be sufficient to use:
>>
>> 'funcname' in __bultins__
>>
>> ...but that doesn't appear to work in pypy 1.4:
>>
>>>>>> print 'platform_version' in platform
>> Traceback (most recent call last):
>> File "<console>", line 1, in <module>
>> TypeError: 'module' object is not iterable
>>>>>> print 'bytes' in __builtins__
>> Traceback (most recent call last):
>> File "<console>", line 1, in <module>
>> TypeError: 'module' object is not iterable
>>>>>>
>
>
>
> --
> Leonardo Santagada
> _______________________________________________
> pypy-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-dev
More information about the Pypy-dev
mailing list