Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dict and __dict__
#1
Here, may i know why when i use
Peter.dict
the following error will occur

Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'Celsius' object has no attribute 'dict'
But when i use
Peter.__dict__
It will work. What's the difference? Many thanks.

class Celsius:
    def __init__(self, temperature = 0):
        self.temperature = temperature

    def to_fahrenheit(self):
        return (self.temperature * 1.8) + 32

Peter = Celsius()
Peter.temperature = 37
Peter.__list__
Reply


Messages In This Thread
dict and __dict__ - by cls0724 - Apr-05-2020, 06:24 AM
RE: dict and __dict__ - by Mateusz - Apr-05-2020, 07:45 PM

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
  Sort a dict in dict cherry_cherry 4 80,803 Apr-08-2020, 12:25 PM
Last Post: perfringo
  what is the __dict__ object? aaron1989041 6 4,827 Mar-29-2018, 05:18 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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