johnf wrote: > def someMethod(): > class MyClass(object): > ..... > if something: > ..... > return someval > > Legal? Well the police won't come after you!
Python allows a class statement anywhere. So this use is part of the language. So the question becomes "why would you want to do that?" Considerations: 1 - this usage creates a local object MyClass. The object will not be visible outside the function. The class definition is executed each time the function is called. 2 - the object could be returned or assigned to a global or added to a parameter that is a collection. 3 - if no instances are created in the function the object will disappear once the function execution ends. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor