On Fri, Dec 3, 2010 at 2:04 PM, Dan Stromberg <[email protected]> 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 > >>>> > > TIA! > _______________________________________________ > [email protected] > http://codespeak.net/mailman/listinfo/pypy-dev > That doesn't work for me on CPython: a...@alex-laptop:~$ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "bytes" in __builtins__ Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: argument of type 'module' is not iterable You can use `hasattr` to check if a module has an attribute (function). Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me
_______________________________________________ [email protected] http://codespeak.net/mailman/listinfo/pypy-dev
