Double sided double underscored variable names

Joshua Landau joshua.landau.ws at gmail.com
Tue Sep 11 18:48:51 EDT 2012


On 11 September 2012 23:22, Chris Angelico <rosuav at gmail.com> wrote:

> On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau
> <joshua.landau.ws at gmail.com> wrote:
> > If I were to use internal double-underscored names of the form
> > __BS_internalname__, would the compiled code be able to assume that
> no-one
> > had overwritten these variables and never will, even through modification
> > of, say, locals(). I ask because Python's docs seem to specify that
> double
> > sided double underscored names are strictly for Python and its special
> > names.
>
> Interesting. If you're compiling your code to Python, you may be able
> to, if necessary, adorn a user's variable name(s). I'd be inclined to
> use a single underscore notation like _BS_internalname_ and then, in
> the event of a collision (which would be incredibly unlikely unless
> someone's fiddling), rename the offending variable to
> _BS_BS_something_ - which of course you'd never yourself use. Would
> that serve?
>

Well, the problem is that a lot of collisions aren't predictable.
"locals()['foo'] = 2", for example. If it weren't for Python's annoying
flexibility* I would definitely do something very close to what you
suggest. Remember that "locals()" isn't Python's only introspection tool.
How about "from foo import *"?

I could just make the claim "You use non-explicitly declared names and you
pay the price", but that seems... less nice.

*Being "annoying" is how I'm pretty sure I can get inline function
definitions working, though, so I shouldn't give it too much rap...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120911/63b1f8ab/attachment.html>


More information about the Python-list mailing list