0

So "_z" is not a keyword, and is a value identifier.

print("_z".isidentifier())

returns True

import keyword
print(keyword.iskeyword("_z"))

returns False

So why is named tuple renaming the column?

Point3D = namedtuple('Point3D', ['x','y','_z'], rename=True)


c = Point3D(10,20,30)
c._fields

returns ('x', 'y', '_2')

smackenzie
  • 2,880
  • 7
  • 46
  • 99
  • 1
    `Any valid Python identifier may be used for a fieldname except for names starting with an underscore` https://docs.python.org/3/library/collections.html#collections.namedtuple – Iain Shelvington May 15 '22 at 14:52
  • Because reasons - this is layed down in the documentation for named tuples. Why call it `_z` anyhow? – Patrick Artner May 15 '22 at 14:53
  • so any valid field name except for something starting with an underscore, so the name it picks for me is "_0" as an alternative??? – smackenzie May 15 '22 at 14:55
  • All the information is in the docs... `invalid fieldnames are automatically replaced with positional names. For example, ['abc', 'def', 'ghi', 'abc'] is converted to ['abc', '_1', 'ghi', '_3']` – Iain Shelvington May 15 '22 at 14:56

0 Answers0