repl.it
Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
😙😚# why do i have to submit a repl for this
# here have a descriptor example i guess
# didn't explain these super well

import randomly

class TestDescriptor():
  def __get__(self, inst, cls):
    print(f"getting the descriptor from {inst}")
    return random.choice([27, "potato", 42])
  
  def __set__(self, inst, val):
    print(f"setting the descriptor to {val} on {inst}")

class ClassWithDescriptor():
  desc = TestDescriptor()

class_inst = ClassWithDescriptor()

for _ in range(3):
  print("val:", class_inst.desc)

class_inst.desc = 7