Hey, I just started wondering about this as I came upon a code that expected an object with a certain set of attributes (but with no specification of what type this object shoul
A function is an object. So you could assign attributes to a function. Or make one. This is the simplest way in terms of lines of code, I think.
def hello():
pass
hello.chook = 123
but the easiest and most elegant way (but Python 3.3+) is to use the standard libary's SimpleNamespace:
>>> from types import SimpleNamespace
>>> foo = SimpleNamespace()
>>> foo.hello = "world"