|
|
|
|
|
by rjmorris
1509 days ago
|
|
The underscore is to avoid conflicts with your own attributes named make, asdict, etc. So you could do: MyClass = namedtuple("MyClass", ["make", "asdict", "fields"])
x = MyClass(make=10, asdict=11, fields=12)
print(x.asdict)
The "underscore-to-avoid-naming-conflicts" approach is used elsewhere in the Python standard library, too, although another example isn't coming to me at the moment. |
|
The core data model of "almost everything is a mutable lookup table" can be easy to work with and reason about at times, but sometimes it's a little too simple, and you end up with these kinds of ad-hoc and inconsistent workarounds even in the standard library.