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