sqlalchemy - How can I "override" deepcopy in Python? -
I want to override __Deepcopy __
for a given SQLAlchemy-mapped class, such as It ignores anybody on the SQLA features of Godkopia, everything else that is part of the class.
I am not particularly aware of overriding the underlying objects of any Python, but I have some ideas that I want. / P>
Creates a very simple class mapped by the SQLA user
class user (object): def __init __ (auto, user_id = none, name = none): self.user_id = user_id self.name = name
I have used the dir ()
to look before and after mapping are SQL-specific attributes and can be sent to _sa_class_manager
and _sa_instance_state
Got it.
questions
provided they are only those that I will ignore it when defining ___________
? Does SQLs inject in mapped objects?
(I did this in the last question (as did a few days after selecting the answer to the main question), but I think that I
It is that as an additional logic, you can send Dipakopi with memorandum
Need to define around a teenager bit of excavation after I tried it out:
def __deepcopy __ (self, memo): dpcpy = self .__ class __ () memo [Id (self)] = dir (self): if not attr.startswith ('_'): value = geta I created an example like ttr (self, ether) setter (dpcp, atri, copy.dppcopy (value, memo)) back dpcp
then i user
: <
snake = user (913, 'nag, s.')
After this, I tried the gig-copy
operation:
snake_dc = copy.deepcopy (snake)
... << P>
for example the user to change his own initPlease try:
def __init __ (self, user_id = none, name = none): map.selfer_id = user_id self.name = name
To make a copy of the examples made, I recommend reading
Comments
Post a Comment