creating class objects inside methods

horos11 horos11 at gmail.com
Sun Oct 4 02:45:39 EDT 2009


> It's not a bug.  In Python classes and global variables share the same
> namespace.
>
> Don't you think you should learn a bit more about how Python manages
> objects and namespaces before going around calling things bugs?
>
> Carl Banks

No, I don't think so..

Say you went to another country, where the people wore lead shoes,
hence not only going slower, but getting lead poisoning from time to
time.

Pointing out that shoes made of fabric might just be better should not
be heresy.

In this case, I think the overall goal was syntax simplicity, but it
sure as hell makes things confusing. No warning, or anything. The sane
behavior IMO would be to disallow the assignment unless put through a
special function, something like:

class(state) = ...

After all, python does have a precedent when you try to join, when:

":".join([1,2])

does not work because [1,2] is an array of ints, whereas

":" . join( str(x) for x in [1,2])

does.

Ed



More information about the Python-list mailing list