FMeinicke's Wiki

Home

❯

Coding

❯

Python

❯

Dynamically add property to a class

Dynamically add property to a class

May 26, 20251 min read

  • python/property

property

Source

  • https://stackoverflow.com/a/1355444/12780516
class Foo:
    ...
 
Foo.dynamic_prop = property(lambda s: "getter", lambda s, v: "setter")
  • also works if there are already instances of that class ⇒ those will have the dynamic property, as well

Graph View

Created with Quartz v4.5.0 © 2025

  • GitHub