Double sided double underscored variable names

Chris Angelico rosuav at gmail.com
Tue Sep 11 18:22:17 EDT 2012


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?

ChrisA



More information about the Python-list mailing list