How to Form a Dictionary from an Object in Python


In this example we will show how to form a dictionary in the object of the class with Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

class A(object):
    def __init__(self):
        self.a = 6
        self.b = 8
    def do_nothing(self):
        pass

c = A()
print(c.__dict__)

Output:

{'b': 8, 'a': 6}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments