[Python-3000] interaction between locals, builtins and except clause
dalcinl at gmail.com
Thu Jul 26 20:34:51 CEST 2007
On 7/26/07, Eduardo EdCrypt O. Padoan <eopadoan at altavix.com> > Python
thinnks range is local, because you referenced it, even if an
> error ocurred. Use 'global range' at the top of the file.
Yes, I understand all that. I just wanted to know if the result of
this locals + except + globals interaction was right, even in the case
of errors. Now I know that it is OK. Thanks!
> But, as I understand, you are trying to target both Python 2.x and 3
> with the same code, using tricks like this one. I think that, even if
> you succeed, the resulting code will be quite unmaintainable.
Well, my code is not so complex in the python side (I'm still
supporting python 2.3). And I do not want to put things in globals,
just for maintenenace reasons. In the end, I've used the following
try: _range = xrange
except: _range = range
for i in _range(n): pass
I think it should work in any 2x and 3K. Is this right? Perhaps this
trick could be used for some automated conversion tool targeting
backward compatibility with 2.x series.
Regards, and thanks again for your clarification.
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
More information about the Python-3000