Albert-Jan Roskam <[email protected]> writes:
> I find the following obscure (to me at least) use of type() useful
> exactly for this "bag of attributes" use case:
>>>> employee = type("Employee", (object,), {})
>>>> employee.name = "John Doe"
>>>> employee.position = "Python programmer"
You could write it as:
class Employee:
name = "Johh Doe"
position = "Python programmer"
It also makes it clear that `type()` returns a *class Employee*, not its
instance (Employee()) and therefore name, position are class attributes.
--
Akira
--
https://mail.python.org/mailman/listinfo/python-list