[Discuss] SQLAlchemy Has Annoyances

Mike Small smallm at panix.com
Thu Feb 5 13:45:56 EST 2015


Richard Pieri <richard.pieri at gmail.com> writes:

> On 2/5/2015 11:47 AM, Mike Small wrote:
>> Does Python's MOP let you add and remove members from classes or are
>> they immutable once created?
>
> If an object (variable, list, class, whatever) isn't a constant then
> it is mutable. Scope may restrict what changes are permitted.

So in his case could he use only one class and map it to many tables?
i.e. when finished with one temporary table and moving on to a second
one, could he sweep out all the old class members (member variables or
methods -- I don't know how the mapping to columns is done here) and add
new ones corresponding to the new set of columns? Would that save this
accumulation of useless classes?  Or would the old members or a snapshot
of the old classes with those members be retained somewhere?  

Now that I think about it, it's kind of puzzling to remove a method or
attribute from a class definition.  E.g. if you remove an attribute from
the class definition after you've created an instance of that class with
a value for that attribute, what kind of object is that object now? Is it
still of the type that class represents or is it of the class before
your change to its definition was made? Or when you remove the attribute
from the class does it find all the instances and release the values
bound to that attribute on each one? Or does Python really let you edit
a class definition in this way at all?

-- 
Mike Small
smallm at panix.com



More information about the Discuss mailing list