[Python-ideas] Object grabbing (was: Re: Python-ideas Digest, Vol 114, Issue 5)

Barry Warsaw barry at python.org
Mon May 2 15:34:20 EDT 2016


On May 02, 2016, at 11:51 AM, Nathaniel Smith wrote:

>I guess the obvious alternative would be
>
>in namespace:
>    ...

Reusing an existing keyword would be better, yes.

>The pandas folks would love to have something like this actually, if it let
>you write
>
>in some_table:
>    total_height = height_feet * 12 + height_inches
>
>instead of the current
>
>some_table["total_height"] = some_table["height_feet"] * 12 +
>some_table["height_inches"]

My first impression was yuk! because it wouldn't be clear to me where to find
those names upon visual inspection of the code.  But after thinking about it,
it seems kind of interesting.

I think what you're proposing is a layering of additional namespaces stack on
(under?) the standard ones.

>Of course this requires that the namespace be accessed via some kind of
>hookable interface, not just a built in object or dict.

Something like:

    class Kevinspacey:
        def __namespace__(self):
            return self.__dict__

Then an instance of Kevinspacey could be used in an in-namespace clause:

    hopper = Kevinspacey()
    in hopper:
        ants = 1

    hopper.ants
    -> 1

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160502/fc6d9849/attachment-0001.sig>


More information about the Python-ideas mailing list