开发者

Delete an object by id in python?

开发者 https://www.devze.com 2023-02-07 05:28 出处:网络
If I get the id of an object, how can I delete an object by it\'开发者_Go百科s id ?This is not a good idea.Try using the weakref module, which allows you to create weak references (analogous to symbol

If I get the id of an object, how can I delete an object by it'开发者_Go百科s id ?


This is not a good idea. Try using the weakref module, which allows you to create weak references (analogous to symbolic links) to objects.


AFAIK objects are deleted by garbage collector in python. You can't force a delete yourself.


The id refers to a memory address. You "can't" delete (or free) a memory address, only its references, with the del statement


You can delete objects by calling del() on them. But AFAIK id won't help in that.

0

精彩评论

暂无评论...
验证码 换一张
取 消