Python
  • index
  • Basic - 1
  • Basic - 2
  • SQLAlchemy
  • Decorator
  • @property
  • __dict__
  • pathlib
  • class
  • flask
  • Jupyter Notebook
  • PyQt
  • UD - FLASK - PY Basic
  • UD - FLASK - REST
  • UD - FLASK - vanilla SQL
  • UD - FLASK - SQLAlchemy
  • UD - FLASK - JWT
  • UD - FLASK - Serialization
Powered by GitBook
On this page

Was this helpful?

__dict__

class Target(object):

    def __init__(self):
        self.a = 1
        self.b = 2


t = Target()
t.__dict__
# {'a': 1, 'b': 2}

reassigning leads to replacement.

t.__dict__ = { 'a': 3 }
t.__dict__
# {'a': 3}

t.b
# AttributeError: 'Target' object has no attribute 'b'

update changes some items only.

t.__dict__ = { 'a': 1, 'b': 2 }
t.__dict__
# {'a': 1, 'b': 2}

t.__dict__.update({'a':10, 'd': 11})
# {'a': 10, 'b': 2, 'd': 11}
t.__dict__
t.b
# 2
Previous@propertyNextpathlib

Last updated 5 years ago

Was this helpful?