Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

module.__dict__ python

class MyClass(object):
    class_var = 1

    def __init__(self, i_var):
        self.i_var = i_var

foo = MyClass(2)
bar = MyClass(3)

print MyClass.__dict__
print foo.__dict__
print bar.__dict__
Comment

__dict__ python?

class DogClass:
    def __init__(self,name,color):
        self.name = name
        self.color = color
    
    def bark(self):
        if self.color == "black":
            return True
        else:
            return False
dc = DogClass('rudra','white')
print(dc.__dict__)
# Output: {'name': 'rudra', 'color': 'white'}

DogClass.__dict__
Comment

module.__dict__ python

{'__module__': '__main__', 'class_var': 1, '__dict__': <attribute '__dict__' of 'MyClass' objects>, '__weakref__': <attribute '__weakref__' of 'MyClass' objects>, '__doc__': None, '__init__': <function __init__ at 0x0000000004E55CF8>}
{'i_var': 2}
{'i_var': 3}

Comment

python __dict__

# __dict__
class A:
    class_var = 1
    def __init__(self) -> None:
        self.a = 2
        self.b = 3

a = A()
print(a.__dict__.items())       
# dict_items([('a', 2), ('b', 3)])
print(A.__dict__.items())
# dict_items([('__module__', '__main__'), ('class_var', 1), 
# ('__init__', <function A.__init__ at 0x00000197277BE320>), 
# ('__dict__', <attribute '__dict__' of 'A' objects>), 
# ('__weakref__', <attribute '__weakref__' of 'A' objects>), ('__doc__', None)])
Comment

PREVIOUS NEXT
Code Example
Python :: get column index pandas 
Python :: Username Promt using Python with Character Limit 
Python :: Genisim python 
Python :: python delete key dictionary 
Python :: colorgram in python 
Python :: pandas como quitar comillas simples de una columna 
Python :: python call function x number of times 
Python :: exclude first value of an array python 
Python :: how to remove element from list python by index 
Python :: return mean of df as dataframe 
Python :: python while 
Python :: how to open pygame 
Python :: how to get the most common number in python 
Python :: digital differential analyzer 
Python :: json to argparse 
Python :: django login required 
Python :: program to add first and last digit of a number in python 
Python :: pil format multiline text 
Python :: dictionary in python 
Python :: Customizable TKinter Buttons Python 
Python :: leetcode matrix diagonal sum in python 
Python :: how to merge two column pandas 
Python :: add gaussian noise python 
Python :: trim string to max length python 
Python :: lowercase python 
Python :: code 
Python :: close a file python 
Python :: fernet in python 
Python :: print binary tree python 
Python :: pandas read csv python 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =