Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not support json key start with "_" #24

Open
JFRabbit opened this issue Mar 18, 2020 · 1 comment
Open

Not support json key start with "_" #24

JFRabbit opened this issue Mar 18, 2020 · 1 comment

Comments

@JFRabbit
Copy link

version: 0.3.3

code:

namedtupled.map({'_key': 1})

result:

Traceback (most recent call last):
  File "/Users/jasonzhang/Documents/xxxxxx.py", line 58, in <module>
    namedtupled.map({'_key': 1})
  File "/Users/jasonzhang/Documents/code/k2assets-data-generator/venv/lib/python3.7/site-packages/namedtupled/namedtupled.py", line 11, in mapper
    return namedtuple_wrapper(_nt_name, **mapping)
  File "/Users/jasonzhang/Documents/code/k2assets-data-generator/venv/lib/python3.7/site-packages/namedtupled/namedtupled.py", line 18, in namedtuple_wrapper
    wrap = namedtuple(_nt_name, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 370, in namedtuple
    raise ValueError('Field names cannot start with an underscore: '
ValueError: Field names cannot start with an underscore: '_key'
@awwwd
Copy link

awwwd commented Mar 2, 2021

Hmm. So the underlying data structure collections.namedtuple doesn't allow any field name starting with underscore. There is a keyword only parameter rename which is set to False by default. But, If set to True then that will rename the fields with the respective positional value.

>>> dummy = namedtuple('dummy', '_foo bar', rename=True)
>>> dummy._fields
('_0', 'bar')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants