[Tutor] is it legal to have a class within a def

Alan Gauld alan.gauld at btinternet.com
Thu Jan 3 09:18:36 CET 2008

"bob gailer" <bgailer at alum.rpi.edu> wrote

> So the question becomes "why would you want to do that?"

The main reason I could think of was to create a factory 
method for dynamically creating classes based on input 
parameters - for example currency convertors or similar.
Equally you could change method implementations 
by passing lambdas etc.

Useful in certain other languages but much less so in 
Python which allows dynamic changes to classes/objects 
after creation anyway.

Alan G.

More information about the Tutor mailing list