Bussiere
Bussiere

Reputation: 1154

Delete an object by id in python?

If I get the id of an object, how can I delete an object by it's id ?

Upvotes: 0

Views: 5323

Answers (4)

Fábio Diniz
Fábio Diniz

Reputation: 10353

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

Upvotes: 0

user113397
user113397

Reputation:

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

Upvotes: 2

erickrf
erickrf

Reputation: 2104

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

Upvotes: -2

gruszczy
gruszczy

Reputation: 42168

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

Upvotes: 1

Related Questions