Reputation: 1
i'm not good at english and i'm noob at python but i have tiny question about python map
are they assigned relation each key and value? if i created some object like this
my_map = {}
my_map['id'] = someObject()
is someObject not Dangling Pointer? is not gonna delete by python interpreter?
Upvotes: 0
Views: 20
Reputation:
Formally:
my_map['id']
is a subscription
then you have:
Assignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects:
...
If the primary is a mapping object (such as a dictionary), the subscript must have a type compatible with the mapping’s key type, and the mapping is then asked to create a key/datum pair which maps the subscript to the assigned object. This can either replace an existing key/value pair with the same key value, or insert a new key/value pair (if no key with the same value existed).
from here Assignment statements
So basically you are binding/mapping the recently created object to the subscript and of course, the newly created object can be referenced by my_map['id']
so the Python garbage collector can't touch it (reclaim it) and it is not a "dangling pointer" or to be more precise an object without any reference to it.
Side note: a dangling pointer is not a term used to refer to an object without reference (how appears you were using the term) but to a reference to a nonvalid object (and this is impossible in Python).
Upvotes: 1
Reputation: 6475
There is no pointer in Python. There is name bound to object in Python.
Upvotes: 0