[issue13678] way to prevent accidental variable overriding

2011-12-29 Thread James Hutchison
New submission from James Hutchison jamesghutchi...@gmail.com: In python is currently there a way to elegantly throw an error if a variable is already in the current scope? For example: def longfunc(self, filename): FILE = open(filename); header = FILE.readline(); ... bunch of

[issue13678] way to prevent accidental variable overriding

2011-12-29 Thread Eric Snow
Eric Snow ericsnowcurren...@gmail.com added the comment: Interesting thought, the syntax seems unnecessary. Adding new syntax to the language is something that happens rarely and only with a _lot_ of consideration. As a slightly more verbose alternative, currently you can do this: def

[issue13678] way to prevent accidental variable overriding

2011-12-29 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: I think this more the domain of pylint/pyflakes. -- nosy: +benjamin.peterson resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org

[issue13678] way to prevent accidental variable overriding

2011-12-29 Thread James Hutchison
James Hutchison jamesghutchi...@gmail.com added the comment: For starters, this would be most efficient implementation: def unique(varname, value, scope): assert(not varname in scope); scope[varname] = value; Usage: unique('b', 1, locals()); print(b); But you can't put that in a loop

[issue13678] way to prevent accidental variable overriding

2011-12-29 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: I suggest you mail python-ideas. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13678 ___