gmr / flatdict

Python module for interacting with nested dicts as a single level dict with delimited keys.
https://flatdict.readthedocs.io
BSD 3-Clause "New" or "Revised" License
111 stars 32 forks source link

all values are transed to str? #23

Closed KeithTt closed 5 years ago

KeithTt commented 6 years ago

In my source dict, values are numbers, how to remain the value type?

source = {
    'a':{
        'b':1,
        'c':2
        },
    'd':{
        'e':3,
        'f':{
            'g':4
            }
        }
}

target = flatdict.FlatDict(source, delimiter='.')
print(target)
# {'a.b': '1', 'a.c': '2', 'd.e': '3', 'd.f.g': '4'}
gmr commented 5 years ago

In this case, you're printing so the values are outputted as strings. I've updated repr and str methods to not coerce output to string for 3.1. There is no assignment coercion taking place in the version you're using other than for printing/string cast methods.