Box icon indicating copy to clipboard operation
Box copied to clipboard

box_dots does not support keys including numbers

Open richieadler opened this issue 6 years ago • 4 comments

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

richieadler avatar Dec 27 '19 14:12 richieadler

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 avatar Dec 27 '19 17:12 cdgriffith

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

MrBillium avatar Jun 02 '20 18:06 MrBillium

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

luckyp70 avatar Mar 02 '22 20:03 luckyp70

@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

cdgriffith avatar Mar 03 '22 01:03 cdgriffith