8000 (Enhancement request) Allow string input for the 'field_names' argument to namedtuple · Issue #1267 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content
(Enhancement request) Allow string input for the 'field_names' argument to namedtuple #1267
Closed
@ddiminnie

Description

@ddiminnie

(Please note that there is absolutely no urgency behind this request - I happened to notice it while porting over some python code, and thought it might be helpful for others...)

When creating a new namedtuple class via the 'collections.namedtuple' factory function, CPython allows the 'field_names' argument to be a string containing whitespace and/or comma-delimited names, e.g.

from collections import namedtuple
foo = namedtuple('foo', 'a b')

However, in CircuitPython (and possibly the parent micropython distribution... though I have no way of verifying this at the moment) this usage triggers a TypeError exception:

>>> from collections import namedtuple
>>> foo = namedtuple('foo', 'a b')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object 'str' is not a tuple or list

The workaround for this is trivial (simply convert the string into a sequence of strings, such as ('a', 'b') for the example above)...
... but it might be nice to not have to convert the code to make it work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0