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

__dict__

shared variable
{'__module__': '__main__', 'class_var': 'shared variable', '__dict__': <attribute '__dict__' of 'Demo' objects>, '__weakref__': <attribute '__weakref__' of 'Demo' objects>, '__doc__': None}
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 :: abstract classes in python 
Python :: python code to press a key 
Python :: inline keyboard telegram bot python 
Python :: age calculator python 
Python :: python pandas if statement 
Python :: shuffle function in python 
Python :: python / vs // 
Python :: pandas append dataframes with same columns 
Python :: do while in python 
Python :: class python example 
Python :: how to use pyplot 
Python :: install python 3.7 
Python :: split long list into chunks of 100 
Python :: runserver coomand in django 
Python :: list unpacking python 
Python :: python string to boolean 
Python :: How to perform heap sort, in Python? 
Python :: how to print even numbers in python 
Python :: slider python 
Python :: set empty dictionary key python 
Python :: average python 
Python :: df.rename(index=str, columns={"A": "a", "C": "c"}) what does index=str means 
Python :: doing math in python 
Python :: eval() function in python 
Python :: naive bayes implementation in python 
Python :: change version of python that poetry use 
Python :: NEW CALENDAR MODULE 
Python :: numpy find index of matching values 
Python :: print statements 
Python :: how to unstack multiindex pandas 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =