fCONV_AUSRICHTG is not defined - Why?

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Nov 7 19:31:03 EST 2023


On 8/11/23 8:10 am, MRAB wrote:
> Something to do with how scoping is implemented in comprehensions?

Yes, together with the way class scopes work during class construction.

Behind the scenes, the body of a listcomp happens to be implemented
as a nested function.

Usually you don't notice this, but while a class is being built,
its scope doesn't count as an enlosing scope for functions defined
within the class.

This is necessary, otherwise all of a class's attributes would be 
visible inside its methods, which isn't what we want. However, it
leads to some odd corner cases, such as this one.

There are various ways you could work around this. I would suggest
moving the offending code outside the class and qualifying the
constants it uses with the class name.

-- 
Greg


More information about the Python-list mailing list