recordtype

raw JSON →
1.4 verified Fri May 01 auth: no python maintenance

Provides a mutable alternative to namedtuple. Users define a class with fields and get a mutable, tuple-like object with named attributes. Last stable version is 1.4, released in 2012. No active development, but still usable. Use with caution in new projects.

pip install recordtype
error AttributeError: module 'recordtype' has no attribute 'recordtype'
cause Importing recordtype incorrectly: import recordtype instead of from recordtype import recordtype.
fix
Use: from recordtype import recordtype
error TypeError: __new__() missing 1 required positional argument: '...'
cause Providing field names as a list or tuple instead of a single space-separated string.
fix
Pass field names as a string: recordtype('Person', 'name age')
error TypeError: cannot unpack non-iterable Person object
cause recordtype does not support tuple unpacking because it is not a tuple subclass.
fix
Access fields by name, not by unpacking. If unpacking is needed, consider namedtuple or dataclasses.
deprecated recordtype has been unmaintained since 2012. Consider using types.SimpleNamespace, dataclasses, or attrs for new projects.
fix Use from dataclasses import dataclass and define a class with fields.
gotcha Field names are specified as a single string with spaces. It's easy to accidentally use commas or other delimiters.
fix Always use a space-separated string: recordtype('Name', 'field1 field2 field3').
gotcha recordtype does not support type hints or validation. Field values can be any type and are not checked.
fix Consider using dataclasses with type annotations if you need type safety.
breaking recordtype returns an object that is not compatible with some pickle protocols due to its internal _fields attribute.
fix If you need pickle, implement __reduce__ manually or switch to a different library.

Creates a mutable record type with named fields.

from recordtype import recordtype

# Define a record type
Person = recordtype('Person', 'name age email')
p = Person('Alice', 30, 'alice@example.com')
print(p.name)  # Alice
p.age = 31     # mutable
print(p.age)   # 31