Life's better without braces

Gerrit Holl gerrit at nl.linux.org
Fri Feb 25 15:38:06 EST 2000


On Fri, Feb 25, 2000 at 07:21:38PM +0100, Bernhard Herzog wrote:
> Is it posssible to implement getattr, setattr and delattr without eval
> or exec?

I don't think so.

> How do you implement len for builtin types without
> iterating through the indices until an IndexError is raised?

You don't.

> How do you implement callable?

def callable(f):
    try:
        f()
        return 1
    except TypeError:
        return 0

Hmm, this is wrong.
What about checkins if... no, I don't know.

> I think you forgot str and cmp, but they're easy:
> 
> def str(obj):
>     return "%s" % (obj,)
> 
> def cmp(a, b):
>     if a > b:
>         return 1
>     if a < b:
>         return -1
>     return 0
> 
> ord should also be possible.

Possible with some dictionairy.

regards,
Gerrit.

-- 
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O !M !V PS+ PE?
Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK-----




More information about the Python-list mailing list