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

box_dots does not support keys including numbers #123

Open
richieadler opened this issue Dec 27, 2019 · 4 comments
Open

box_dots does not support keys including numbers #123

richieadler opened this issue Dec 27, 2019 · 4 comments

Comments

@richieadler
Copy link

Windows 7, Python 3.7.3, Box 4.0.3

#!/usr/bin/env python3

import box

info = box.Box({'uno': {2: 'tres', 'cuatro': 5}}, default_box=True, box_dots=True)

print(info['uno'][2])
# tres

print(info['uno.2'])
# {}
# it should be:
# tres

print(info['uno']['cuatro'])
# 5

print(info.uno.cuatro)
# 5

print(info['uno.cuatro'])
# 5
@cdgriffith
Copy link
Owner

While this would be a nice to have, that would be very costly to try and convert all keys to do string lookups on. At minimum I need to mention that limiting factor in the readme for now.

@cdgriffith cdgriffith changed the title Problem with box_dots and keys including numbers box_dots does not support keys including numbers Dec 27, 2019
@MrBillium
Copy link

Please note that keys starting with numbers don't work in Box either.
In my case I was using 25percent
changing key to p25percent DID work

cdgriffith added a commit that referenced this issue Feb 14, 2022
… variable on get request (thanks to ipcoder)

* Changing #123 box_dots to convert ints and bytes as needed (thanks to Marcelo Huerta)
* Changing #192 box_dots and box_default to split and create sub dictionaries as needed for insertion (thanks to Rexbard)
@luckyp70
Copy link

luckyp70 commented Mar 2, 2022

Keys including "-" don't work either. I had to replace "-" with "_".

@cdgriffith
Copy link
Owner

@MrBillium @luckyp70 do you have code samples you can share? I am not able to duplicate.

from box import Box

my_box = Box(box_dots=True)

my_box['22test'] = {'33-test': {'sub2': 'a'}}

print(my_box)
# {'22test': {'33-test': {'sub2': 'a'}}}

print(my_box['22test.33-test.sub2'])
# a

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

No branches or pull requests

4 participants