Python Forum
what is the __dict__ object?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what is the __dict__ object?
#4
(Mar-28-2018, 09:29 AM)aaron1989041 Wrote: i think if id() function gives the same address for two objects,they must be the same object.
Use code tags.
There not same object,but something strange happens when making into a tuple object.
>>> class A:
...     pass
...
... class B:
...     pass

>>> id(A.__dict__)
62085776

>>> id(B.__dict__)
62373680
So when use , between object,Python is making a tuple.
This is when the somewhat strange execution happens.
>>> id(A.__dict__), id(B.__dict__)
(136355152, 136355152)
It look like when using special method in tuple creation it call same object.
>>> a = 'foo'
>>> b = 'bar'

>>> id(a)
128252192
>>> id(b)
61876128

>>> id(a), id(b)
(128252192, 61876128)
Using .__add__ the same happens.
>>> id(a.__add__), id(b.__add__)
(62304752, 62304752) 
Nothing to worry about,
this is some internal stuff with id() and special method in tuple creation.
Reply


Messages In This Thread
what is the __dict__ object? - by aaron1989041 - Mar-28-2018, 02:44 AM
RE: what is the __dict__ object? - by Larz60+ - Mar-28-2018, 05:53 AM
RE: what is the __dict__ object? - by snippsat - Mar-28-2018, 01:32 PM
RE: what is the __dict__ object? - by wavic - Mar-28-2018, 03:25 PM
RE: what is the __dict__ object? - by aaron1989041 - Mar-29-2018, 02:15 AM
RE: what is the __dict__ object? - by Gribouillis - Mar-29-2018, 05:18 AM
id() function is strange - by aaron1989041 - Mar-28-2018, 09:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  __dict__ in math library akbarza 6 1,000 Sep-28-2023, 08:23 AM
Last Post: buran
  dict and __dict__ cls0724 1 2,722 Apr-05-2020, 07:45 PM
Last Post: Mateusz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020