[Python-ideas] namedtuple nit...
Chris Barker
chris.barker at noaa.gov
Thu Jul 27 12:26:34 EDT 2017
Since we are talking about namedtuple and implementation, I just noticed:
In [22]: Point = namedtuple('Point', ['x', 'y'])
In [23]: p = Point(2,3)
In [24]: p.x = 5
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-24-328d3fab3e30> in <module>()
----> 1 p.x = 5
AttributeError: can't set attribute
OK -- that makes sense. but then, if you try:
In [25]: p.z = 5
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-625ed954d865> in <module>()
----> 1 p.z = 5
AttributeError: 'Point' object has no attribute 'z'
I think this should be a different message -- key here is that you can't
set a new attribute, not that one doesn't exist. Maybe:
"AttributeError: can't set new attribute"
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170727/1aa35112/attachment-0001.html>
More information about the Python-ideas
mailing list