classes — reading what ai just wrote you9 / 9
instance vs class attributes — and the bug ai ships every time
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill. Build a User class that uses both buckets correctly:
- Class attribute
domain = "example.com"(a constant — same for every user). - Instance attributes (assigned in
__init__):username(passed in)permissions— an empty list (must be per-instance)
- Method
email()returnsf"{self.username}@{self.domain}". - Method
grant(perm)appendspermtoself.permissions.
Two users, distinct permission lists, shared domain string.
Expected output:
maya@example.com
marcus@example.com
['read']
['read', 'write']
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _