<div class="gmail_quote">On 11 September 2012 23:22, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

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

<div><br></div><div>I could just make the claim "You use non-explicitly declared names and you pay the price", but that seems... less nice.</div><div><br></div><div>*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...</div>