Classes as namespaces?

Terry Reedy tjreedy at
Sat Mar 27 18:10:22 CET 2010

On 3/27/2010 7:28 AM, Jonathan Hartley wrote:
> On Mar 26, 6:26 pm, Luis M. González<luis... at>  wrote:

> But defining and then calling the function like that is a tad
> cumbersome. So I was wondering about:
> x = 1
> class account_for_non_square_pixels:
>    ((some complex logic))
> y = 2
> I don't exactly like this, but I think you can see what I'm getting
> at. Does this fall down in some way I haven't grasped?

The assignments within the class are performed within a new local 
namespace. So moving non-toy code within a class block will typically fail.

More information about the Python-list mailing list